-
Notifications
You must be signed in to change notification settings - Fork 3
/
BaseMapper_test.go
73 lines (62 loc) · 1.5 KB
/
BaseMapper_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
package xjgorm
import (
"fmt"
"github.com/xjieinfo/xjgo/xjcore/xjgorm"
"github.com/xjieinfo/xjgo/xjcore/xjtypes"
"testing"
)
var baseMapper BaseMapper
func init() {
dsn := "root:root@tcp(localhost:3306)/test?charset=utf8mb4&parseTime=true"
datasource := xjtypes.Datasource{
Drivername: "mysql",
Dsn: dsn,
}
baseMapper.Gorm = xjgorm.GormInit(datasource)
}
type Student struct {
ID int
Username string
Address string
}
func (this Student) TableName() string {
return "student"
}
func Test_Create(t *testing.T) {
item := Student{
Username: "张三",
Address: "长沙市",
}
flag, _ := baseMapper.Create(&item)
fmt.Println(flag)
}
func Test_Save(t *testing.T) {
var item Student
baseMapper.First(new(xjtypes.GormWrapper).Eq("id", 2), &item)
item.Address = "星沙"
flag, _ := baseMapper.Save(&item)
fmt.Println(flag)
}
func Test_Delete(t *testing.T) {
var item Student
flag, _ := baseMapper.Delete(new(xjtypes.GormWrapper).Eq("id", 2), &item)
fmt.Println(flag)
}
func Test_Find(t *testing.T) {
var list []Student
baseMapper.Find(new(xjtypes.GormWrapper).Eq("username", "张三"), &list)
fmt.Println(list)
}
func Test_Count(t *testing.T) {
var item Student
var total int64
baseMapper.Count(new(xjtypes.GormWrapper).Eq("username", "张三"), &item, &total)
fmt.Println(total)
}
func Test_ListCount(t *testing.T) {
var list []Student
var total int64
baseMapper.FindCount(new(xjtypes.GormWrapper).Eq("username", "张三"), &list, &total)
fmt.Println(list)
fmt.Println(total)
}