-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxbase_test.go
110 lines (91 loc) · 2.18 KB
/
xbase_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package xdominion
import (
"fmt"
"testing"
)
func ExampleXBase() {
base := &XBase{
DBType: DB_Postgres,
Username: "username",
Password: "password",
Database: "test",
Host: DB_Localhost,
SSL: false,
}
base.Logon()
}
func TestXCore_exec(t *testing.T) {
}
func TestXCore_commit(t *testing.T) {
base := &XBase{
DBType: DB_Postgres,
Username: "username",
Password: "password",
Database: "test",
Host: DB_Localhost,
SSL: false,
}
base.Logon()
tb := getTableDef(base)
fmt.Println(tb.Synchronize())
// insert
res1, err := tb.Insert(XRecord{"f1": 3, "f2": "Data line 1"})
if err != nil {
fmt.Println(err)
}
fmt.Println(res1)
res2, err := tb.Insert(XRecord{"f1": 4, "f2": "Data line 2"})
if err != nil {
fmt.Println(err)
}
fmt.Println(res2)
tx, err := base.BeginTransaction()
// insert
res3, err := tb.Insert(XRecord{"f1": 5, "f2": "Data line 1"}, tx)
if err != nil {
fmt.Println(err)
}
fmt.Println(res3)
res4, err := tb.Insert(XRecord{"f1": 6, "f2": "Data line 2"}, tx)
if err != nil {
fmt.Println(err)
}
fmt.Println(res4)
res41, err := tb.Update(XRecord{"f3": "some new data"}, tx)
if err != nil {
fmt.Println(err)
}
fmt.Println(res41)
res42, err := tb.Delete(1, tx)
if err != nil {
fmt.Println(err)
}
fmt.Println(res42)
// lets roll back
err = tx.Commit()
if err != nil {
fmt.Println(err)
}
// should give an error, tx is rollbacked
res5, err := tb.Insert(XRecord{"f1": 7, "f2": "Data line 2"}, tx)
if err != nil {
fmt.Println(err)
}
fmt.Println(res5)
}
func getTableDef(base *XBase) *XTable {
t := NewXTable("test", "t_")
t.AddField(XFieldInteger{Name: "f1", Constraints: XConstraints{
XConstraint{Type: PK},
XConstraint{Type: AI},
}}) // ai, pk
t.AddField(XFieldVarChar{Name: "f2", Size: 20, Constraints: XConstraints{
XConstraint{Type: NN},
}})
t.AddField(XFieldText{Name: "f3"})
t.AddField(XFieldDate{Name: "f4", Constraints: XConstraints{XConstraint{Type: IN}}})
t.AddField(XFieldDateTime{Name: "f5", Constraints: XConstraints{XConstraint{Type: UI}}})
t.AddField(XFieldFloat{Name: "f6", Constraints: XConstraints{XConstraint{Type: MU, Data: []string{"f4", "f5"}}}})
t.SetBase(base)
return t
}