Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions column.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ func NewBaseColumn(name string, sqltype string, tagmap map[string]string, isPoin
if ok {
dbName = val
}
tagmap, val, ok = utils.TagPop(tagmap, TAG_SQL_NAME)
if ok {
dbName = val
}
oldName := ""
tagmap, val, ok = utils.TagPop(tagmap, TAG_OLD_NAME)
if ok {
Expand Down
51 changes: 51 additions & 0 deletions column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,57 @@ func TestBaseColumns(t *testing.T) {
colIndex: -1,
},
},
{
name: "test",
sqlType: "TEXT",
tags: map[string]string{"primary": "true", "index": "true", "name": "test_"},
isPointer: false,
want: SBaseColumn{
name: "test",
dbName: "test_",
sqlType: "TEXT",
isPointer: false,
isNullable: false,
isPrimary: true,
isIndex: true,
tags: make(map[string]string),
colIndex: -1,
},
},
{
name: "test",
sqlType: "TEXT",
tags: map[string]string{"primary": "true", "index": "true", "name": "test_", "sql_name": "test2_"},
isPointer: false,
want: SBaseColumn{
name: "test",
dbName: "test2_",
sqlType: "TEXT",
isPointer: false,
isNullable: false,
isPrimary: true,
isIndex: true,
tags: make(map[string]string),
colIndex: -1,
},
},
{
name: "test",
sqlType: "TEXT",
tags: map[string]string{"primary": "true", "index": "true", "sql_name": "test2_"},
isPointer: false,
want: SBaseColumn{
name: "test",
dbName: "test2_",
sqlType: "TEXT",
isPointer: false,
isNullable: false,
isPrimary: true,
isIndex: true,
tags: make(map[string]string),
colIndex: -1,
},
},
}
for _, c := range cases {
got := NewBaseColumn(c.name, c.sqlType, c.tags, c.isPointer)
Expand Down
4 changes: 3 additions & 1 deletion const.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ const (
const (
// TAG_IGNORE is a field tag that indicates the field is ignored, not represents a table column
TAG_IGNORE = "ignore"
// TAG_NAME is a field tag that indicates the column name of this field
// TAG_NAME is a field tag that indicates the column name of this field, obsolete, use TAG_SQL_NAME instead!
TAG_NAME = "name"
// TAG_SQL_NAME is a field tag that indicates the column name of this field, superceeds TAG_NAME!
TAG_SQL_NAME = "sql_name"
// TAG_WIDTH is a field tag that indicates the width of the column, like VARCHAR(15)
// Supported by: mysql
TAG_WIDTH = "width"
Expand Down