2013-08-08 05:24:38 +00:00
|
|
|
package xorm
|
|
|
|
|
|
|
|
import (
|
2013-12-18 03:31:32 +00:00
|
|
|
"database/sql"
|
|
|
|
"testing"
|
2013-12-16 15:42:31 +00:00
|
|
|
|
2013-12-18 03:31:32 +00:00
|
|
|
_ "github.com/lib/pq"
|
2013-08-08 05:24:38 +00:00
|
|
|
)
|
|
|
|
|
2013-12-04 07:03:21 +00:00
|
|
|
func newPostgresEngine() (*Engine, error) {
|
2013-12-18 03:31:32 +00:00
|
|
|
return NewEngine("postgres", "dbname=xorm_test sslmode=disable")
|
2013-12-04 07:03:21 +00:00
|
|
|
}
|
|
|
|
|
2013-12-16 15:42:31 +00:00
|
|
|
func newPostgresDriverDB() (*sql.DB, error) {
|
2013-12-18 03:31:32 +00:00
|
|
|
return sql.Open("postgres", "dbname=xorm_test sslmode=disable")
|
2013-12-16 15:42:31 +00:00
|
|
|
}
|
2013-11-16 16:52:43 +00:00
|
|
|
|
2013-12-16 15:42:31 +00:00
|
|
|
func TestPostgres(t *testing.T) {
|
2013-12-18 03:31:32 +00:00
|
|
|
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)
|
2013-11-16 16:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostgresWithCache(t *testing.T) {
|
2013-12-18 03:31:32 +00:00
|
|
|
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)
|
2013-09-26 07:19:39 +00:00
|
|
|
}
|
|
|
|
|
2013-11-15 03:01:13 +00:00
|
|
|
/*
|
2013-09-26 07:19:39 +00:00
|
|
|
func TestPostgres2(t *testing.T) {
|
2013-12-09 02:29:23 +00:00
|
|
|
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{}
|
2013-09-26 07:19:39 +00:00
|
|
|
|
2013-12-09 02:29:23 +00:00
|
|
|
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)
|
2013-11-15 03:01:13 +00:00
|
|
|
}*/
|
2013-09-28 15:14:42 +00:00
|
|
|
|
2013-12-16 15:42:31 +00:00
|
|
|
const (
|
2013-12-18 03:31:32 +00:00
|
|
|
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";`
|
2013-12-16 15:42:31 +00:00
|
|
|
)
|
2013-12-04 07:03:21 +00:00
|
|
|
|
2013-12-16 15:42:31 +00:00
|
|
|
func BenchmarkPostgresDriverInsert(t *testing.B) {
|
2013-12-18 03:31:32 +00:00
|
|
|
doBenchDriver(newPostgresDriverDB, createTablePostgres, dropTablePostgres,
|
|
|
|
doBenchDriverInsert, t)
|
2013-12-04 07:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkPostgresDriverFind(t *testing.B) {
|
2013-12-18 03:31:32 +00:00
|
|
|
doBenchDriver(newPostgresDriverDB, createTablePostgres, dropTablePostgres,
|
|
|
|
doBenchDriverFind, t)
|
2013-12-16 15:42:31 +00:00
|
|
|
}
|
2013-12-04 07:03:21 +00:00
|
|
|
|
|
|
|
func BenchmarkPostgresNoCacheInsert(t *testing.B) {
|
2013-12-18 03:31:32 +00:00
|
|
|
engine, err := newPostgresEngine()
|
|
|
|
|
|
|
|
defer engine.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
//engine.ShowSQL = true
|
|
|
|
doBenchInsert(engine, t)
|
2013-09-28 15:14:42 +00:00
|
|
|
}
|
|
|
|
|
2013-12-04 07:03:21 +00:00
|
|
|
func BenchmarkPostgresNoCacheFind(t *testing.B) {
|
2013-12-18 03:31:32 +00:00
|
|
|
engine, err := newPostgresEngine()
|
|
|
|
|
|
|
|
defer engine.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
//engine.ShowSQL = true
|
|
|
|
doBenchFind(engine, t)
|
2013-12-04 07:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkPostgresNoCacheFindPtr(t *testing.B) {
|
2013-12-18 03:31:32 +00:00
|
|
|
engine, err := newPostgresEngine()
|
|
|
|
|
|
|
|
defer engine.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
//engine.ShowSQL = true
|
|
|
|
doBenchFindPtr(engine, t)
|
2013-12-04 07:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkPostgresCacheInsert(t *testing.B) {
|
2013-12-18 03:31:32 +00:00
|
|
|
engine, err := newPostgresEngine()
|
2013-12-04 07:03:21 +00:00
|
|
|
|
2013-12-18 03:31:32 +00:00
|
|
|
defer engine.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
engine.SetDefaultCacher(NewLRUCacher(NewMemoryStore(), 1000))
|
2013-12-04 07:03:21 +00:00
|
|
|
|
2013-12-18 03:31:32 +00:00
|
|
|
doBenchInsert(engine, t)
|
2013-12-04 07:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkPostgresCacheFind(t *testing.B) {
|
2013-12-18 03:31:32 +00:00
|
|
|
engine, err := newPostgresEngine()
|
2013-12-04 07:03:21 +00:00
|
|
|
|
2013-12-18 03:31:32 +00:00
|
|
|
defer engine.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
engine.SetDefaultCacher(NewLRUCacher(NewMemoryStore(), 1000))
|
2013-12-04 07:03:21 +00:00
|
|
|
|
2013-12-18 03:31:32 +00:00
|
|
|
doBenchFind(engine, t)
|
2013-12-04 07:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkPostgresCacheFindPtr(t *testing.B) {
|
2013-12-18 03:31:32 +00:00
|
|
|
engine, err := newPostgresEngine()
|
2013-09-28 15:14:42 +00:00
|
|
|
|
2013-12-18 03:31:32 +00:00
|
|
|
defer engine.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
engine.SetDefaultCacher(NewLRUCacher(NewMemoryStore(), 1000))
|
2013-12-04 07:03:21 +00:00
|
|
|
|
2013-12-18 03:31:32 +00:00
|
|
|
doBenchFindPtr(engine, t)
|
2013-09-28 15:14:42 +00:00
|
|
|
}
|