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"