forked from gocraft/dbr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert_test.go
42 lines (36 loc) · 943 Bytes
/
insert_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
package dbr
import (
"testing"
"github.com/gocraft/dbr/dialect"
"github.com/stretchr/testify/assert"
)
type insertTest struct {
A int
C string `db:"b"`
}
func TestInsertStmt(t *testing.T) {
buf := NewBuffer()
builder := InsertInto("table").Columns("a", "b").Values(1, "one").Record(&insertTest{
A: 2,
C: "two",
})
err := builder.Build(dialect.MySQL, buf)
assert.NoError(t, err)
assert.Equal(t, "INSERT INTO `table` (`a`,`b`) VALUES (?,?), (?,?)", buf.String())
assert.Equal(t, []interface{}{1, "one", 2, "two"}, buf.Value())
}
func BenchmarkInsertValuesSQL(b *testing.B) {
buf := NewBuffer()
for i := 0; i < b.N; i++ {
InsertInto("table").Columns("a", "b").Values(1, "one").Build(dialect.MySQL, buf)
}
}
func BenchmarkInsertRecordSQL(b *testing.B) {
buf := NewBuffer()
for i := 0; i < b.N; i++ {
InsertInto("table").Columns("a", "b").Record(&insertTest{
A: 2,
C: "two",
}).Build(dialect.MySQL, buf)
}
}