forked from wenj91/gobatis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gobatis_test.go
80 lines (65 loc) · 1.63 KB
/
gobatis_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
package gobatis
import (
"context"
"fmt"
_ "github.com/go-sql-driver/mysql"
"testing"
)
type TUser struct {
Id int64 `field:"id"`
Name string `field:"name"`
Password NullString `field:"pwd"`
Email NullString `field:"email"`
CrtTm NullTime `field:"crtTm"`
}
func TestGoBatis(t *testing.T) {
batis, e := NewGoBatis(context.Background(), nil)
if nil != e {
panic(e)
}
gb, e := batis.Begin()
//result := make(map[string]interface{})
//result := make([]interface{}, 0)
//var result interface{}
//result := make([]TUser, 0)
var result *TUser
err := gb.Select("userMapper.findById", map[string]interface{}{
"id": 2,
})(&result)
fmt.Println("result:", result, "err:", err)
u := &TUser{
Name: "wenj1991",
Password: NullString{
String: "654321",
Valid: true,
},
}
id, a, err := gb.Insert("userMapper.saveUser", u)
fmt.Println("id:", id, "affected:", a, "err:", err)
uu := &TUser{
Id: 1,
Name: "wenj1993",
Password: NullString{
String: "654321",
Valid: true,
},
}
// test set
affected, err := gb.Update("userMapper.updateByCond", uu)
fmt.Println("updateByCond:", affected, err)
param := &TUser{
Name: "wenj1993",
}
// test where
res := make([]*TUser, 0)
err = gb.Select("userMapper.queryStructsByCond", param)(&res)
fmt.Println("queryStructsByCond", res, err)
// test trim
res2 := make([]*TUser, 0)
err = gb.Select("userMapper.queryStructsByCond2", param)(&res2)
fmt.Println("queryStructsByCond", res2, err)
affected, err = gb.Delete("userMapper.deleteById", map[string]interface{}{
"id": 3,
})
fmt.Println("delete affected:", affected, "err:", err)
}