resolved #67
This commit is contained in:
parent
069f551119
commit
8700152b6c
|
@ -759,7 +759,7 @@ func (engine *Engine) mapType(v reflect.Value) *core.Table {
|
||||||
if ormTagStr != "" {
|
if ormTagStr != "" {
|
||||||
col = &core.Column{FieldName: t.Field(i).Name, Nullable: true, IsPrimaryKey: false,
|
col = &core.Column{FieldName: t.Field(i).Name, Nullable: true, IsPrimaryKey: false,
|
||||||
IsAutoIncrement: false, MapType: core.TWOSIDES, Indexes: make(map[string]bool)}
|
IsAutoIncrement: false, MapType: core.TWOSIDES, Indexes: make(map[string]bool)}
|
||||||
tags := strings.Split(ormTagStr, " ")
|
tags := splitTag(ormTagStr)
|
||||||
|
|
||||||
if len(tags) > 0 {
|
if len(tags) > 0 {
|
||||||
if tags[0] == "-" {
|
if tags[0] == "-" {
|
||||||
|
|
20
helpers.go
20
helpers.go
|
@ -15,6 +15,26 @@ import (
|
||||||
"github.com/go-xorm/core"
|
"github.com/go-xorm/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func splitTag(tag string) (tags []string) {
|
||||||
|
tag = strings.TrimSpace(tag)
|
||||||
|
var hasQuote = false
|
||||||
|
var lastIdx = 0
|
||||||
|
for i, t := range tag {
|
||||||
|
if t == '\'' {
|
||||||
|
hasQuote = !hasQuote
|
||||||
|
} else if t == ' ' {
|
||||||
|
if lastIdx < i && !hasQuote {
|
||||||
|
tags = append(tags, strings.TrimSpace(tag[lastIdx:i]))
|
||||||
|
lastIdx = i + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if lastIdx < len(tag) {
|
||||||
|
tags = append(tags, strings.TrimSpace(tag[lastIdx:len(tag)]))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
type zeroable interface {
|
type zeroable interface {
|
||||||
IsZero() bool
|
IsZero() bool
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package xorm
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestSplitTag(t *testing.T) {
|
||||||
|
var cases = []struct {
|
||||||
|
tag string
|
||||||
|
tags []string
|
||||||
|
}{
|
||||||
|
{"not null default '2000-01-01 00:00:00' TIMESTAMP", []string{"not", "null", "default", "'2000-01-01 00:00:00'", "TIMESTAMP"}},
|
||||||
|
{"TEXT", []string{"TEXT"}},
|
||||||
|
{"default('2000-01-01 00:00:00')", []string{"default('2000-01-01 00:00:00')"}},
|
||||||
|
{"json binary", []string{"json", "binary"}},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, kase := range cases {
|
||||||
|
tags := splitTag(kase.tag)
|
||||||
|
if !sliceEq(tags, kase.tags) {
|
||||||
|
t.Fatalf("[%d]%v is not equal [%d]%v", len(tags), tags, len(kase.tags), kase.tags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue