forked from gohouse/gorose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
orm_test.go
62 lines (55 loc) · 1.16 KB
/
orm_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
package gorose
import (
"testing"
)
func DB() IOrm {
return initDB().NewOrm()
}
func TestNewOrm(t *testing.T) {
orm := DB()
orm.Hello()
}
func TestOrm_AddFields(t *testing.T) {
orm := DB()
//var u = Users{}
var fieldStmt = orm.Table("users").Fields("a").Where("m", 55)
a, b, err := fieldStmt.AddFields("b").Where("d", 1).BuildSql()
if err != nil {
t.Error(err.Error())
}
t.Log(a, b)
fieldStmt.Reset()
d, e, err := fieldStmt.Fields("a").AddFields("c").Where("d", 2).BuildSql()
if err != nil {
t.Error(err.Error())
}
t.Log(d, e)
}
func TestOrm_BuildSql(t *testing.T) {
var u = Users{
Name: "gorose2",
Age: 19,
}
//aff, err := db.Force().Data(&u)
a, b, err := DB().Table(&u).Where("age", ">", 1).Data(&u).BuildSql("update")
if err != nil {
t.Error(err.Error())
}
t.Log(a, b)
}
func TestOrm_BuildSql_where(t *testing.T) {
var u = Users{
Name: "gorose2",
Age: 19,
}
var db = DB()
a, b, err := db.Table(&u).Where("age", ">", 1).Where(func() {
db.Where("name", "like", "%fizz%").OrWhere(func() {
db.Where("age", ">", 10).Where("uid", ">", 2)
})
}).Limit(2).Offset(2).BuildSql()
if err != nil {
t.Error(err.Error())
}
t.Log(a, b)
}