fix: SQL `UPDATE SET` is missing spaces

This commit is contained in:
demoManito 2023-10-20 19:28:40 +08:00
parent 6bef318891
commit e9c3b25552
6 changed files with 31 additions and 16 deletions

View File

@ -18,9 +18,12 @@ func (set Set) Build(builder Builder) {
for idx, assignment := range set {
if idx > 0 {
builder.WriteByte(',')
builder.WriteByte(' ')
}
builder.WriteQuoted(assignment.Column)
builder.WriteByte(' ')
builder.WriteByte('=')
builder.WriteByte(' ')
builder.AddVar(builder, assignment.Value)
}
} else {

View File

@ -32,6 +32,18 @@ func TestSet(t *testing.T) {
"UPDATE `users` SET `name` = ?",
[]interface{}{"jinzhu"},
},
{
[]clause.Interface{
clause.Update{},
clause.Set([]clause.Assignment{{clause.PrimaryColumn, 1}}),
clause.Set([]clause.Assignment{
{clause.Column{Name: "name"}, "jinzhu"},
{clause.Column{Name: "age"}, 18},
}),
},
"UPDATE `users` SET `name` = ?, `age` = ?",
[]interface{}{"jinzhu", 18},
},
}
for idx, result := range results {