-
Notifications
You must be signed in to change notification settings - Fork 0
/
r_test.go
87 lines (74 loc) · 2.04 KB
/
r_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
package sqlr
import (
"testing"
)
func TestR_Insert(t *testing.T) {
var SQL = "(`username`,`gender`,`password`,`avatar`,`cover`,`created`,`update`) VALUES (?,?,?,?,?,?,?)"
var Vals = []any{"张三", 1, "123456", "https://www.demo.com/avatar.png", "https://www.demo.com/cover.png", 86400, 86400}
var r = new(R).
Pair("username", "张三").
Pair("gender", 1).
Map(map[string]any{"password": "123456"}).
Struct(struct {
Avatar string `db:"avatar"`
Cover string `db:"cover"`
}{
Avatar: "https://www.demo.com/avatar.png",
Cover: "https://www.demo.com/cover.png",
}, "db").
ShareV(86400, "created", "update")
var partSQL = r.Insert()
if SQL != partSQL {
t.Error("SQL拼接错误")
}
var values = r.V()
for i := 0; i < len(Vals); i++ {
if Vals[i] != values[i] {
t.Error("参数结果列表错误")
}
}
}
func TestR_Update(t *testing.T) {
var SQL = "`username` = ?,`gender` = ?,`password` = ?,`avatar` = ?,`cover` = ?,`update` = ?"
var Vals = []any{"张三", 1, "123456", "https://www.demo.com/avatar.png", "https://www.demo.com/cover.png", 86400}
var r = new(R).
Pair("username", "张三").
Pair("gender", 1).
Map(map[string]any{"password": "123456"}).
Struct(struct {
Avatar string `db:"avatar"`
Cover string `db:"cover"`
}{
Avatar: "https://www.demo.com/avatar.png",
Cover: "https://www.demo.com/cover.png",
}, "db").
Pair("update", 86400)
var partSQL = r.Update()
if SQL != partSQL {
t.Error("SQL拼接错误", partSQL)
}
var values = r.V()
for i := 0; i < len(Vals); i++ {
if Vals[i] != values[i] {
t.Error("参数结果列表错误")
}
}
}
func TestR_Where(t *testing.T) {
var SQL = "username = ? AND gender = ? AND update > ?"
var Vals = []any{"张三", 1, 86400}
var r = new(R).
Pair("username = ?", "张三").
Pair("gender = ?", 1).
Pair("update > ?", 86400)
var partSQL = r.Where()
if SQL != partSQL {
t.Error("SQL拼接错误", partSQL)
}
var values = r.V()
for i := 0; i < len(Vals); i++ {
if Vals[i] != values[i] {
t.Error("参数结果列表错误")
}
}
}