-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinsert_test.go
62 lines (57 loc) · 1.3 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package gomysql
import (
"testing"
)
type MeStruct struct {
X int `json:"x"`
Y int `json:"y"`
Z int `json:"z"`
}
type Person struct {
ID int64 `db:"id,default"`
FirstName string `db:"first_name,force"`
LastName string `db:"last_name"`
Email string `db:"email,force"`
Me MeStruct `db:"me"`
Uids []int64 `db:"uids"`
TestJson string `db:"test"`
Age int `json:"age" db:"age,counter"`
}
func TestInsert(t *testing.T) {
conf := Sqlconfig{
UserName: "test",
Password: "123456",
Port: 3306,
DbName: "test",
Host: "192.168.50.250",
MultiStatements: true,
}
db, err := conf.NewMysqlDb()
if err != nil {
t.Fatal(err)
}
ps := &Person{
FirstName: "cander",
LastName: "biao",
Email: "[email protected]",
Me: MeStruct{
X: 10,
Y: 20,
Z: 30,
},
TestJson: "testaaaa",
Uids: []int64{5, 7, 23, 12, 90},
Age: 1,
}
// pss := make([]*Person, 0)
// for i := 0; i < 20; i++ {
// pss = append(pss, ps)
// }
// $key $value 是固定占位符
// default: 如果设置了并且为零值, 那么为数据库的默认值
// struct, 指针, 切片 默认值为 ""
res := db.InsertInterfaceWithoutID(ps, "insert into person($key) values($value)")
if res.Err != nil {
t.Fatal(err)
}
}