This repository has been archived by the owner on Jun 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtestGet.go
90 lines (76 loc) · 1.47 KB
/
testGet.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
86
87
88
89
90
package tests
import (
"errors"
"fmt"
"testing"
"github.com/go-xorm/xorm"
)
func get(engine *xorm.Engine, t *testing.T) {
getStruct(engine, t)
// FIXME: uncomment this after we support get non-struct
//getInt(engine, t)
}
type NoIdUser struct {
User string `xorm:"unique"`
Remain int64
Total int64
}
func getStruct(engine *xorm.Engine, t *testing.T) {
user := Userinfo{Uid: 2}
has, err := engine.Get(&user)
if err != nil {
t.Error(err)
panic(err)
}
if has {
fmt.Println(user)
} else {
fmt.Println("no record id is 2")
}
err = engine.Sync(&NoIdUser{})
if err != nil {
t.Error(err)
panic(err)
}
userCol := engine.ColumnMapper.Obj2Table("User")
_, err = engine.Where("`"+userCol+"` = ?", "xlw").Delete(&NoIdUser{})
if err != nil {
t.Error(err)
panic(err)
}
cnt, err := engine.Insert(&NoIdUser{"xlw", 20, 100})
if err != nil {
t.Error(err)
panic(err)
}
if cnt != 1 {
err = errors.New("insert not returned 1")
t.Error(err)
panic(err)
}
noIdUser := new(NoIdUser)
has, err = engine.Where("`"+userCol+"` = ?", "xlw").Get(noIdUser)
if err != nil {
t.Error(err)
panic(err)
}
if !has {
err = errors.New("get not returned 1")
t.Error(err)
panic(err)
}
fmt.Println(noIdUser)
}
func getInt(engine *xorm.Engine, t *testing.T) {
var id int64
has, err := engine.Table("userinfo").Cols("uid").Get(&id)
if err != nil {
t.Error(err)
panic(err)
}
if has {
fmt.Println(id)
} else {
fmt.Println("no record id is 2")
}
}