-
Notifications
You must be signed in to change notification settings - Fork 36
/
update_test.go
43 lines (35 loc) · 1.1 KB
/
update_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package dbr
import (
"testing"
"github.com/mailru/dbr/dialect"
"github.com/stretchr/testify/assert"
)
func TestUpdateStmt(t *testing.T) {
buf := NewBuffer()
builder := Update("table").Set("a", 1).Where(Eq("b", 2))
err := builder.Build(dialect.MySQL, buf)
assert.NoError(t, err)
assert.Equal(t, "UPDATE `table` SET `a` = ? WHERE (`b` = ?)", buf.String())
assert.Equal(t, []interface{}{1, 2}, buf.Value())
}
func TestUpdateStmtSetRecord(t *testing.T) {
record := struct{ A int }{A: 1}
buf := NewBuffer()
builder := Update("table").SetRecord(&record).Where(Eq("b", 2))
err := builder.Build(dialect.MySQL, buf)
assert.NoError(t, err)
assert.Equal(t, "UPDATE `table` SET `a` = ? WHERE (`b` = ?)", buf.String())
assert.Equal(t, []interface{}{1, 2}, buf.Value())
}
func BenchmarkUpdateValuesSQL(b *testing.B) {
buf := NewBuffer()
for i := 0; i < b.N; i++ {
Update("table").Set("a", 1).Build(dialect.MySQL, buf)
}
}
func BenchmarkUpdateMapSQL(b *testing.B) {
buf := NewBuffer()
for i := 0; i < b.N; i++ {
Update("table").SetMap(map[string]interface{}{"a": 1, "b": 2}).Build(dialect.MySQL, buf)
}
}