forked from sabrinalua/simple-sql-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
named-exec-helper_test.go
85 lines (70 loc) · 1.78 KB
/
named-exec-helper_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
package helper
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type db struct {
Name string `db:"name"`
Time *time.Time `db:"time"`
}
func Test_ExecInsertHelper(t *testing.T) {
d := db{}
assert := assert.New(t)
helper, e := NewNamedExecHelper("dbTable", d)
assert.NoError(e)
helper.SetIgnoreTags("time")
s := helper.InsertQuery()
fmt.Println("s", s)
}
func Test_SelectQuery(t *testing.T) {
d := db{}
assert := assert.New(t)
helper, e := NewNamedExecHelper("dbTable", d)
assert.NoError(e)
helper.SetIgnoreTags("time")
s := helper.SelectQuery(nil, "name")
fmt.Println("s", s)
}
func Test_SelectQueryWithCond(t *testing.T) {
d := db{}
assert := assert.New(t)
helper, e := NewNamedExecHelper("dbTable", d)
assert.NoError(e)
helper.SetIgnoreTags("time")
c1 := ConditionEqual("name", "david")
c2 := ConditionNotEqual("age", 15)
cb := NewConditionBuilder(c1)
cb.And(c2)
s := helper.SelectQuery(cb)
fmt.Println("s", s)
}
func Test_Upsert(t *testing.T) {
d := db{}
assert := assert.New(t)
helper, e := NewNamedExecHelper("dbTable", d)
assert.NoError(e)
helper.SetIgnoreTags("time")
c1 := ConditionEqual("name", "david")
c2 := ConditionNotEqual("age", 15)
cb := NewConditionBuilder(c1)
cb.And(c2)
s := helper.UpsertQuery(cb, "name")
aliases := helper.AliasMap
fmt.Println(s, aliases)
}
func Test_UpsertDefault(t *testing.T) {
d := db{}
assert := assert.New(t)
helper, e := NewNamedExecHelper("dbTable", d)
assert.NoError(e)
// helper.SetIgnoreTags("time")
c1 := ConditionEqual("name", "david")
c2 := ConditionNotEqual("age", 15)
cb := NewConditionBuilder(c1)
cb.And(c2)
s := helper.UpsertQuery(cb)
aliases := helper.AliasMap
fmt.Println(s, aliases)
}