forked from gocraft/dbr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_test.go
More file actions
32 lines (26 loc) · 764 Bytes
/
update_test.go
File metadata and controls
32 lines (26 loc) · 764 Bytes
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
package dbr
import (
"testing"
"github.com/gocraft/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 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)
}
}