-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexplain_test.go
46 lines (42 loc) · 989 Bytes
/
explain_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
package dbs_test
import (
"github.com/smartwalle/dbs"
"testing"
)
func TestExplain(t *testing.T) {
type AliasInt int
var tests = []struct {
Clause dbs.SQLClause
ExpectSQL string
}{
{
Clause: dbs.SQL("id = ?", 10),
ExpectSQL: "id = 10",
},
{
Clause: dbs.SQL("id = ?", AliasInt(10)),
ExpectSQL: "id = 10",
},
{
Clause: dbs.SQL("id IN (?)", []int{1, 2, 3, 4, 5}),
ExpectSQL: "id IN (1,2,3,4,5)",
},
{
Clause: dbs.SQL("id IN (?)", []AliasInt{1, 2, 3, 4, 5}),
ExpectSQL: "id IN (1,2,3,4,5)",
},
{
Clause: dbs.SQL("id = (?)", dbs.SQL("SELECT id FROM user where phone = ?", "12345678901")),
ExpectSQL: "id = (SELECT id FROM user where phone = '12345678901')",
},
}
for _, test := range tests {
var sql, err = dbs.Explain(test.Clause)
if err != nil {
t.Fatal("生成 SQL 语句发生错误:", err)
}
if sql != test.ExpectSQL {
t.Fatalf("期望 SQL: %s, 实际 SQL: %s", test.ExpectSQL, sql)
}
}
}