Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithTenantSchema ¶
WithTenantSchema alters the table name to prefix it with the tenant schema. Intended to be used with a postgres database.
The table name is retrieved from the statement if set manually, otherwise attempts to get it from the model or destination.
Example with table name set manually:
type Book struct { ... } // does not implement Tabler interface, must set TableName manually
db.Table("books").Scopes(scopes.WithTenantSchema("tenant1")).Find(&Book{})
// SELECT * FROM tenant1.books;
Example with Tabler interface:
type Book struct { ... }
func (u *Book) TableName() string { return "books" } // implements Tabler interface, no need to set TableName manually
db.Scopes(scopes.WithTenantSchema("tenant2")).Find(&Book{})
// SELECT * FROM tenant2.books;
Example with model set manually:
type Book struct { ... }
db.Model(&Book{}).Scopes(scopes.WithTenantSchema("tenant3")).Find(&Book{}) // model is set manually.
// SELECT * FROM tenant3.books;
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.