@@ -12,35 +12,51 @@ import (
12
12
"github.com/sunary/sqlize/utils"
13
13
)
14
14
15
+ // Tag prefixes
15
16
const (
16
- // SqlTagDefault ...
17
17
SqlTagDefault = "sql"
18
- tagIsSquash = "squash"
19
- tagIsEmbedded = "embedded"
20
18
prefixColumn = "column:" // set column name, eg: 'column:column_name'
21
19
prefixEmbedded = "embedded_prefix:" // set embed prefix for flatten struct, eg: 'embedded_prefix:base_'
22
20
prefixPreviousName = ",previous:" // mark previous name-field, eg: 'column:column_name,previous:old_name'
23
21
prefixType = "type:" // set field type, eg: 'type:VARCHAR(64)'
24
22
prefixDefault = "default:" // set default value, eg: 'default:0'
25
- tagEnum = "enum" // type:ENUM('open','close')
26
23
prefixComment = "comment:" // comment field, eg: 'comment:sth you want to comment'
24
+ )
25
+
26
+ // Special tags
27
+ const (
28
+ tagIsSquash = "squash"
29
+ tagIsEmbedded = "embedded"
30
+ tagEnum = "enum" // type:ENUM('open','close')
31
+ )
27
32
33
+ // Null and key constraints
34
+ const (
28
35
tagIsNull = "null"
29
36
tagIsNotNull = "not_null"
30
37
tagIsAutoIncrement = "auto_increment"
31
38
tagIsPrimaryKey = "primary_key" // this field is primary key, eg: 'primary_key'
32
- tagIsIndex = "index" // indexing this field, eg: 'index' (=> idx_column_name)
33
- tagIsUniqueIndex = "unique" // unique indexing this field, eg: 'unique' (=> idx_column_name)
39
+ )
34
40
41
+ // Index related
42
+ const (
43
+ tagIsIndex = "index" // indexing this field, eg: 'index' (=> idx_column_name)
44
+ tagIsUniqueIndex = "unique" // unique indexing this field, eg: 'unique' (=> idx_column_name)
35
45
prefixIndex = "index:" // indexing with name, eg: 'index:idx_name'
36
46
prefixUniqueIndex = "unique:" // unique indexing with name, eg: 'unique:idx_name'
37
47
prefixIndexColumns = "index_columns:" // indexing these fields, eg: 'index_columns:col1,col2' (=> idx_col1_col2)
38
48
prefixIndexType = "index_type:" // indexing with type, eg: 'index_type:btree' (default) or 'index_type:hash'
49
+ )
39
50
51
+ // Foreign key related
52
+ const (
40
53
prefixForeignKey = "foreign_key:" // 'foreign_key:'
41
54
prefixFkReferences = "references:" // 'references:'
42
55
prefixFkConstraint = "constraint:" // 'constraint:'
56
+ )
43
57
58
+ // Function names
59
+ const (
44
60
funcTableName = "TableName"
45
61
)
46
62
@@ -140,21 +156,30 @@ func (s SqlBuilder) AddTable(obj interface{}) string {
140
156
}
141
157
142
158
type attrs struct {
143
- Name string
144
- Prefix string
145
- Type string
146
- Value string
147
- IsPk bool
148
- ForeignKey * fkAttrs
149
- IsUnique bool
159
+ // Basic attributes
160
+ Name string
161
+ Prefix string
162
+ Type string
163
+ Value string
164
+ Comment string
165
+
166
+ // Key and constraint attributes
167
+ IsPk bool
168
+ IsUnique bool
169
+ IsNull bool
170
+ IsNotNull bool
171
+ IsAutoIncr bool
172
+
173
+ // Foreign key
174
+ ForeignKey * fkAttrs
175
+
176
+ // Index attributes
150
177
Index string
151
178
IndexType string
152
179
IndexColumns string
153
- IsNull bool
154
- IsNotNull bool
155
- IsAutoIncr bool
156
- Comment string
157
- IsEmbedded bool
180
+
181
+ // Special attribute
182
+ IsEmbedded bool
158
183
}
159
184
160
185
type fkAttrs struct {
0 commit comments