Skip to content

Commit b018084

Browse files
authored
Merge pull request #215 from swordqiu/hotfix/qj-use-sql-name-for-colume-name
fix: use sql_name for specifing DB colume name
2 parents 4ca0766 + 0590292 commit b018084

3 files changed

Lines changed: 58 additions & 1 deletion

File tree

column.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ func NewBaseColumn(name string, sqltype string, tagmap map[string]string, isPoin
319319
if ok {
320320
dbName = val
321321
}
322+
tagmap, val, ok = utils.TagPop(tagmap, TAG_SQL_NAME)
323+
if ok {
324+
dbName = val
325+
}
322326
oldName := ""
323327
tagmap, val, ok = utils.TagPop(tagmap, TAG_OLD_NAME)
324328
if ok {

column_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,57 @@ func TestBaseColumns(t *testing.T) {
6464
colIndex: -1,
6565
},
6666
},
67+
{
68+
name: "test",
69+
sqlType: "TEXT",
70+
tags: map[string]string{"primary": "true", "index": "true", "name": "test_"},
71+
isPointer: false,
72+
want: SBaseColumn{
73+
name: "test",
74+
dbName: "test_",
75+
sqlType: "TEXT",
76+
isPointer: false,
77+
isNullable: false,
78+
isPrimary: true,
79+
isIndex: true,
80+
tags: make(map[string]string),
81+
colIndex: -1,
82+
},
83+
},
84+
{
85+
name: "test",
86+
sqlType: "TEXT",
87+
tags: map[string]string{"primary": "true", "index": "true", "name": "test_", "sql_name": "test2_"},
88+
isPointer: false,
89+
want: SBaseColumn{
90+
name: "test",
91+
dbName: "test2_",
92+
sqlType: "TEXT",
93+
isPointer: false,
94+
isNullable: false,
95+
isPrimary: true,
96+
isIndex: true,
97+
tags: make(map[string]string),
98+
colIndex: -1,
99+
},
100+
},
101+
{
102+
name: "test",
103+
sqlType: "TEXT",
104+
tags: map[string]string{"primary": "true", "index": "true", "sql_name": "test2_"},
105+
isPointer: false,
106+
want: SBaseColumn{
107+
name: "test",
108+
dbName: "test2_",
109+
sqlType: "TEXT",
110+
isPointer: false,
111+
isNullable: false,
112+
isPrimary: true,
113+
isIndex: true,
114+
tags: make(map[string]string),
115+
colIndex: -1,
116+
},
117+
},
67118
}
68119
for _, c := range cases {
69120
got := NewBaseColumn(c.name, c.sqlType, c.tags, c.isPointer)

const.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ const (
4848
const (
4949
// TAG_IGNORE is a field tag that indicates the field is ignored, not represents a table column
5050
TAG_IGNORE = "ignore"
51-
// TAG_NAME is a field tag that indicates the column name of this field
51+
// TAG_NAME is a field tag that indicates the column name of this field, obsolete, use TAG_SQL_NAME instead!
5252
TAG_NAME = "name"
53+
// TAG_SQL_NAME is a field tag that indicates the column name of this field, superceeds TAG_NAME!
54+
TAG_SQL_NAME = "sql_name"
5355
// TAG_WIDTH is a field tag that indicates the width of the column, like VARCHAR(15)
5456
// Supported by: mysql
5557
TAG_WIDTH = "width"

0 commit comments

Comments
 (0)