This repository has been archived by the owner on Jul 11, 2019. It is now read-only.
forked from go-xorm/xorm
-
Notifications
You must be signed in to change notification settings - Fork 7
/
postgres_test.go
241 lines (211 loc) · 6.91 KB
/
postgres_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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
package xorm
import (
"database/sql"
"testing"
_ "github.com/lib/pq"
)
//var connStr string = "dbname=xorm_test user=lunny password=1234 sslmode=disable"
var connStr string = "dbname=xorm_test sslmode=disable"
func newPostgresEngine() (*Engine, error) {
return NewEngine("postgres", connStr)
}
func newPostgresDriverDB() (*sql.DB, error) {
return sql.Open("postgres", connStr)
}
func TestPostgres(t *testing.T) {
engine, err := newPostgresEngine()
if err != nil {
t.Error(err)
return
}
defer engine.Close()
engine.ShowSQL = showTestSql
engine.ShowErr = showTestSql
engine.ShowWarn = showTestSql
engine.ShowDebug = showTestSql
testAll(engine, t)
testAll2(engine, t)
testAll3(engine, t)
}
func TestPostgresWithCache(t *testing.T) {
engine, err := newPostgresEngine()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewLRUCacher(NewMemoryStore(), 1000))
defer engine.Close()
engine.ShowSQL = showTestSql
engine.ShowErr = showTestSql
engine.ShowWarn = showTestSql
engine.ShowDebug = showTestSql
testAll(engine, t)
testAll2(engine, t)
}
/*
func TestPostgres2(t *testing.T) {
engine, err := NewEngine("postgres", "dbname=xorm_test sslmode=disable")
if err != nil {
t.Error(err)
return
}
defer engine.Close()
engine.ShowSQL = showTestSql
engine.Mapper = SameMapper{}
fmt.Println("-------------- directCreateTable --------------")
directCreateTable(engine, t)
fmt.Println("-------------- mapper --------------")
mapper(engine, t)
fmt.Println("-------------- insert --------------")
insert(engine, t)
fmt.Println("-------------- querySameMapper --------------")
querySameMapper(engine, t)
fmt.Println("-------------- execSameMapper --------------")
execSameMapper(engine, t)
fmt.Println("-------------- insertAutoIncr --------------")
insertAutoIncr(engine, t)
fmt.Println("-------------- insertMulti --------------")
insertMulti(engine, t)
fmt.Println("-------------- insertTwoTable --------------")
insertTwoTable(engine, t)
fmt.Println("-------------- updateSameMapper --------------")
updateSameMapper(engine, t)
fmt.Println("-------------- testdelete --------------")
testdelete(engine, t)
fmt.Println("-------------- get --------------")
get(engine, t)
fmt.Println("-------------- cascadeGet --------------")
cascadeGet(engine, t)
fmt.Println("-------------- find --------------")
find(engine, t)
fmt.Println("-------------- find2 --------------")
find2(engine, t)
fmt.Println("-------------- findMap --------------")
findMap(engine, t)
fmt.Println("-------------- findMap2 --------------")
findMap2(engine, t)
fmt.Println("-------------- count --------------")
count(engine, t)
fmt.Println("-------------- where --------------")
where(engine, t)
fmt.Println("-------------- in --------------")
in(engine, t)
fmt.Println("-------------- limit --------------")
limit(engine, t)
fmt.Println("-------------- orderSameMapper --------------")
orderSameMapper(engine, t)
fmt.Println("-------------- joinSameMapper --------------")
joinSameMapper(engine, t)
fmt.Println("-------------- havingSameMapper --------------")
havingSameMapper(engine, t)
fmt.Println("-------------- combineTransactionSameMapper --------------")
combineTransactionSameMapper(engine, t)
fmt.Println("-------------- table --------------")
table(engine, t)
fmt.Println("-------------- createMultiTables --------------")
createMultiTables(engine, t)
fmt.Println("-------------- tableOp --------------")
tableOp(engine, t)
fmt.Println("-------------- testColsSameMapper --------------")
testColsSameMapper(engine, t)
fmt.Println("-------------- testCharst --------------")
testCharst(engine, t)
fmt.Println("-------------- testStoreEngine --------------")
testStoreEngine(engine, t)
fmt.Println("-------------- testExtends --------------")
testExtends(engine, t)
fmt.Println("-------------- testColTypes --------------")
testColTypes(engine, t)
fmt.Println("-------------- testCustomType --------------")
testCustomType(engine, t)
fmt.Println("-------------- testCreatedAndUpdated --------------")
testCreatedAndUpdated(engine, t)
fmt.Println("-------------- testIndexAndUnique --------------")
testIndexAndUnique(engine, t)
fmt.Println("-------------- testMetaInfo --------------")
testMetaInfo(engine, t)
fmt.Println("-------------- testIterate --------------")
testIterate(engine, t)
fmt.Println("-------------- testStrangeName --------------")
testStrangeName(engine, t)
fmt.Println("-------------- testVersion --------------")
testVersion(engine, t)
fmt.Println("-------------- testDistinct --------------")
testDistinct(engine, t)
fmt.Println("-------------- testUseBool --------------")
testUseBool(engine, t)
fmt.Println("-------------- transaction --------------")
transaction(engine, t)
}*/
const (
createTablePostgres = `CREATE TABLE IF NOT EXISTS "big_struct" ("id" SERIAL PRIMARY KEY NOT NULL, "name" VARCHAR(255) NULL, "title" VARCHAR(255) NULL, "age" VARCHAR(255) NULL, "alias" VARCHAR(255) NULL, "nick_name" VARCHAR(255) NULL);`
dropTablePostgres = `DROP TABLE IF EXISTS "big_struct";`
)
func BenchmarkPostgresDriverInsert(t *testing.B) {
doBenchDriver(newPostgresDriverDB, createTablePostgres, dropTablePostgres,
doBenchDriverInsert, t)
}
func BenchmarkPostgresDriverFind(t *testing.B) {
doBenchDriver(newPostgresDriverDB, createTablePostgres, dropTablePostgres,
doBenchDriverFind, t)
}
func BenchmarkPostgresNoCacheInsert(t *testing.B) {
engine, err := newPostgresEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
//engine.ShowSQL = true
doBenchInsert(engine, t)
}
func BenchmarkPostgresNoCacheFind(t *testing.B) {
engine, err := newPostgresEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
//engine.ShowSQL = true
doBenchFind(engine, t)
}
func BenchmarkPostgresNoCacheFindPtr(t *testing.B) {
engine, err := newPostgresEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
//engine.ShowSQL = true
doBenchFindPtr(engine, t)
}
func BenchmarkPostgresCacheInsert(t *testing.B) {
engine, err := newPostgresEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewLRUCacher(NewMemoryStore(), 1000))
doBenchInsert(engine, t)
}
func BenchmarkPostgresCacheFind(t *testing.B) {
engine, err := newPostgresEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewLRUCacher(NewMemoryStore(), 1000))
doBenchFind(engine, t)
}
func BenchmarkPostgresCacheFindPtr(t *testing.B) {
engine, err := newPostgresEngine()
defer engine.Close()
if err != nil {
t.Error(err)
return
}
engine.SetDefaultCacher(NewLRUCacher(NewMemoryStore(), 1000))
doBenchFindPtr(engine, t)
}