Skip to content

Commit a5009b0

Browse files
committed
fix bugs
1 parent 8da35cc commit a5009b0

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

orm/create_struct.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ func getTableDbColumns[T Table](query *Query[T]) ([]dBColumn, error) {
192192
if len(cols) == 1 && cols[0] == keyNameAndCols[0] {
193193
keyName = uniqueKeyPrefix
194194
} else {
195-
keyName = uniqueKeyPrefix + "_" + keyName
195+
keyName = uniqueKeyPrefix + ":" + keyName
196196
}
197197
for k2, v2 := range cols {
198198
colName := strings.Trim(v2, "`")
199199
if len(cols) > 1 {
200-
ret[existColumn[colName]].Uniques = append(ret[existColumn[colName]].Uniques, keyName+"("+strconv.Itoa(k2)+")")
200+
ret[existColumn[colName]].Uniques = append(ret[existColumn[colName]].Uniques, keyName+":"+strconv.Itoa(k2))
201201
} else {
202202
ret[existColumn[colName]].Uniques = append(ret[existColumn[colName]].Uniques, keyName)
203203
}
@@ -215,13 +215,13 @@ func getTableDbColumns[T Table](query *Query[T]) ([]dBColumn, error) {
215215
if len(cols) == 1 && cols[0] == keyNameAndCols[0] {
216216
keyName = keyPrefix
217217
} else {
218-
keyName = keyPrefix + "_" + keyName
218+
keyName = keyPrefix + ":" + keyName
219219
}
220220
for k2, v2 := range cols {
221221
colName := strings.Trim(v2, "`")
222222

223223
if len(cols) > 1 {
224-
ret[existColumn[colName]].Indexs = append(ret[existColumn[colName]].Indexs, keyName+"("+strconv.Itoa(k2)+")")
224+
ret[existColumn[colName]].Indexs = append(ret[existColumn[colName]].Indexs, keyName+":"+strconv.Itoa(k2))
225225
} else {
226226
ret[existColumn[colName]].Indexs = append(ret[existColumn[colName]].Indexs, keyName)
227227
}

orm/create_table.go

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,16 @@ func generateColumnStrings(dbColums []dBColumn) []string {
159159

160160
if len(v.Uniques) > 0 {
161161
for _, v2 := range v.Uniques {
162-
if strings.HasSuffix(v2, ")") {
163-
li := strings.LastIndex(v2, "(")
164-
if li > 0 {
165-
numStr := v2[li+1 : len(v2)-1]
166-
num, numErr := strconv.Atoi(numStr)
167-
if numErr == nil {
168-
if uniqueComps[v2[:li]] == nil {
169-
uniqueComps[v2[:li]] = make([]string, 16)
170-
}
171-
uniqueComps[v2[:li]][num] = v.Name
172-
continue
162+
li := strings.LastIndex(v2, ":")
163+
if li > 0 {
164+
numStr := v2[li+1:]
165+
num, numErr := strconv.Atoi(numStr)
166+
if numErr == nil {
167+
if uniqueComps[v2[:li]] == nil {
168+
uniqueComps[v2[:li]] = make([]string, 16)
173169
}
170+
uniqueComps[v2[:li]][num] = v.Name
171+
continue
174172
}
175173
}
176174
uniqueComps[v2] = append(uniqueComps[v2], v.Name)
@@ -180,18 +178,16 @@ func generateColumnStrings(dbColums []dBColumn) []string {
180178

181179
if len(v.Indexs) > 0 {
182180
for _, v2 := range v.Indexs {
183-
if strings.HasSuffix(v2, ")") {
184-
li := strings.LastIndex(v2, "(")
185-
if li > 0 {
186-
numStr := v2[li+1 : len(v2)-1]
187-
num, numErr := strconv.Atoi(numStr)
188-
if numErr == nil {
189-
if indexComps[v2[:li]] == nil {
190-
indexComps[v2[:li]] = make([]string, 16)
191-
}
192-
indexComps[v2[:li]][num] = v.Name
193-
continue
181+
li := strings.LastIndex(v2, ":")
182+
if li > 0 {
183+
numStr := v2[li+1:]
184+
num, numErr := strconv.Atoi(numStr)
185+
if numErr == nil {
186+
if indexComps[v2[:li]] == nil {
187+
indexComps[v2[:li]] = make([]string, 16)
194188
}
189+
indexComps[v2[:li]][num] = v.Name
190+
continue
195191
}
196192
}
197193
indexComps[v2] = append(indexComps[v2], v.Name)
@@ -312,13 +308,13 @@ func getMigrateColumns(table *queryTable) []dBColumn {
312308
if v == uniqueKeyPrefix {
313309
column.Unique = true
314310
} else {
315-
column.Uniques = append(column.Uniques, strings.TrimPrefix(v, uniqueKeyPrefix+"_"))
311+
column.Uniques = append(column.Uniques, strings.TrimPrefix(v, uniqueKeyPrefix+":"))
316312
}
317313
} else if strings.HasPrefix(v, keyPrefix) {
318314
if v == keyPrefix {
319315
column.Index = true
320316
} else {
321-
column.Indexs = append(column.Indexs, strings.TrimPrefix(v, keyPrefix+"_"))
317+
column.Indexs = append(column.Indexs, strings.TrimPrefix(v, keyPrefix+":"))
322318
}
323319
} else {
324320
overideColumn.Type = v

0 commit comments

Comments
 (0)