-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsqlxb_test.go
107 lines (83 loc) · 1.46 KB
/
sqlxb_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package sqlxb
import (
"fmt"
"strings"
"testing"
)
type Cat struct {
Id int64
M map[string]string
}
type Pet struct {
One Cat
Id int64
Body []byte
}
func (*Pet) TableName() string {
return "t_pet"
}
func TestInsert(t *testing.T) {
t.Run("insert", func(t *testing.T) {
mm := make(map[string]string)
mm["xxxx"] = "zzzzz"
body := []byte("xxxxxxxxxxx")
var po Pet
sql, vs := Of(&po).
Insert(func(b *InsertBuilder) {
b.Set("id", 1).
Set("one", Cat{
Id: 2,
M: mm,
}).
Set("body", body)
}).
Build().
SqlOfInsert()
if !strings.Contains(sql, "one") {
t.Error("sql erro")
}
fmt.Println(vs)
fmt.Println(sql)
})
}
func TestUpdate(t *testing.T) {
t.Run("update", func(t *testing.T) {
mm := make(map[string]string)
mm["xxxx"] = "zzzzz"
var po Pet
sql, vs := Of(&po).
Update(func(b *UpdateBuilder) {
b.Set("one", Cat{
Id: 2,
M: mm,
}).
Set("body", []byte("yyyyyyyyyyyy"))
}).
Eq("id", 2).
Build().
SqlOfUpdate()
if !strings.Contains(sql, "one") {
t.Error("sql erro")
}
fmt.Println(vs)
fmt.Println(sql)
})
}
func TestDelete(t *testing.T) {
t.Run("delete", func(t *testing.T) {
var po Pet
sql, vs := Of(&po).Eq("id", 2).
Any(func(x *BuilderX) {
if po.Id != 4 {
x.Gt("id", 1)
}
}).
Build().
SqlOfDelete()
if !strings.Contains(sql, "t_pet") {
t.Error("sql erro")
}
fmt.Println(vs)
fmt.Println(sql)
})
}