From 46c423a89fefe82928aad2d27497bd6f90aeebaa Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 10 Mar 2020 20:42:13 +0800 Subject: [PATCH] Ignore schema when dbtype is not postgres --- dialects/dialect.go | 8 ++++++++ engine.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dialects/dialect.go b/dialects/dialect.go index 35139817..4b9976f7 100644 --- a/dialects/dialect.go +++ b/dialects/dialect.go @@ -14,6 +14,7 @@ import ( "xorm.io/xorm/schemas" ) +// URI represents an uri to visit database type URI struct { DBType schemas.DBType Proto string @@ -29,6 +30,13 @@ type URI struct { Schema string } +// SetSchema set schema +func (uri URI) SetSchema(schema string) { + if uri.DBType == schemas.POSTGRES { + uri.Schema = schema + } +} + // Dialect represents a kind of database type Dialect interface { Init(*core.DB, *URI) error diff --git a/engine.go b/engine.go index 6dd4df3e..bc1d8b5f 100644 --- a/engine.go +++ b/engine.go @@ -1245,7 +1245,7 @@ func (engine *Engine) SetTZDatabase(tz *time.Location) { // SetSchema sets the schema of database func (engine *Engine) SetSchema(schema string) { - engine.dialect.URI().Schema = schema + engine.dialect.URI().SetSchema(schema) } // Unscoped always disable struct tag "deleted" -- 2.40.1