From 062799c9a542ee93582a70590f3554feab1600f5 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 8 Apr 2018 23:20:55 +0800 Subject: [PATCH] add SetSchema for engine --- circle.yml | 5 ++++- engine.go | 5 +++++ interface.go | 1 + xorm_test.go | 5 ++++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index 69fc7164..09fd7da7 100644 --- a/circle.yml +++ b/circle.yml @@ -17,6 +17,7 @@ database: - createdb -p 5432 -e -U postgres xorm_test1 - createdb -p 5432 -e -U postgres xorm_test2 - createdb -p 5432 -e -U postgres xorm_test3 + - psql xorm_test lunny -c "create schema xorm" test: override: @@ -30,7 +31,9 @@ test: - go test -v -race -db="mymysql" -conn_str="xorm_test/root/" -cache=true -coverprofile=coverage3-2.txt -covermode=atomic - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -coverprofile=coverage4-1.txt -covermode=atomic - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -cache=true -coverprofile=coverage4-2.txt -covermode=atomic - - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt > coverage.txt + - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -coverprofile=coverage5-1.txt -covermode=atomic + - go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic + - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt > coverage.txt - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./sqlite3.sh - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./mysql.sh - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./postgres.sh diff --git a/engine.go b/engine.go index 29415cae..95a0184a 100644 --- a/engine.go +++ b/engine.go @@ -1649,6 +1649,11 @@ func (engine *Engine) SetTZDatabase(tz *time.Location) { engine.DatabaseTZ = tz } +// SetSchema sets the schema of database +func (engine *Engine) SetSchema(schema string) { + engine.dialect.URI().Schema = schema +} + // Unscoped always disable struct tag "deleted" func (engine *Engine) Unscoped() *Session { session := engine.NewSession() diff --git a/interface.go b/interface.go index 85a46a27..42a8fe25 100644 --- a/interface.go +++ b/interface.go @@ -87,6 +87,7 @@ type EngineInterface interface { SetDefaultCacher(core.Cacher) SetLogLevel(core.LogLevel) SetMapper(core.IMapper) + SetSchema(string) SetTZDatabase(tz *time.Location) SetTZLocation(tz *time.Location) ShowSQL(show ...bool) diff --git a/xorm_test.go b/xorm_test.go index 569bc681..4e88dc40 100644 --- a/xorm_test.go +++ b/xorm_test.go @@ -27,6 +27,7 @@ var ( cache = flag.Bool("cache", false, "if enable cache") cluster = flag.Bool("cluster", false, "if this is a cluster") splitter = flag.String("splitter", ";", "the splitter on connstr for cluster") + schema = flag.String("schema", "", "specify the schema") ) func createEngine(dbType, connStr string) error { @@ -35,7 +36,6 @@ func createEngine(dbType, connStr string) error { if !*cluster { testEngine, err = NewEngine(dbType, connStr) - } else { testEngine, err = NewEngineGroup(dbType, strings.Split(connStr, *splitter)) } @@ -43,6 +43,9 @@ func createEngine(dbType, connStr string) error { return err } + if *schema != "" { + testEngine.SetSchema(*schema) + } testEngine.ShowSQL(*showSQL) testEngine.SetLogLevel(core.LOG_DEBUG) if *cache {