diff --git a/column.go b/column.go index 1546927..8d36917 100644 --- a/column.go +++ b/column.go @@ -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 { diff --git a/column_test.go b/column_test.go index 4530663..43aebfb 100644 --- a/column_test.go +++ b/column_test.go @@ -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) diff --git a/const.go b/const.go index 35d59ed..9a9eb13 100644 --- a/const.go +++ b/const.go @@ -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"