Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
twz915 committed Sep 12, 2023
1 parent 6f5c96e commit d0122c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion builder/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ func buildInsertOnDuplicate(table string, data []map[string]interface{}, update

func resolveUpdate(update map[string]interface{}) (sets string, vals []interface{}) {
keys := make([]string, 0, len(update))
for key := range update {
keys = append(keys, key)
}
defaultSortAlgorithm(keys)
var sb strings.Builder
for _, k := range keys {
Expand All @@ -417,7 +420,7 @@ func resolveUpdate(update map[string]interface{}) (sets string, vals []interface
continue
}
vals = append(vals, v)
sets += fmt.Sprintf("%s=?,", quoteField(k))
sb.WriteString(fmt.Sprintf("%s=?,", quoteField(k)))
}
sets = strings.TrimRight(sb.String(), ",")
return sets, vals
Expand Down
6 changes: 3 additions & 3 deletions builder/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,21 @@ func TestResolveUpdate(t *testing.T) {
outVals []interface{}
}{
{
map[string]interface{}{
in: map[string]interface{}{
"foo": "bar",
"bar": 1,
},
outStr: "bar=?,foo=?",
outVals: []interface{}{1, "bar"},
},
{
map[string]interface{}{
in: map[string]interface{}{
"qq": "ttt",
"some": 123,
"other": 456,
},
outStr: "other=?,qq=?,some=?",
[]interface{}{456, "ttt", 123},
outVals: []interface{}{456, "ttt", 123},
},
{
in: map[string]interface{}{ // mysql5.7
Expand Down

0 comments on commit d0122c2

Please sign in to comment.