Documentation ¶
Overview ¶
Package scopes provides a set of predefined GORM scopes for managing multi-tenant applications using the gorm-multitenancy library.
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.
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(WithTenantSchema("tenant2")).Find(&Book{}) // SELECT * FROM "tenant2"."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(WithTenantSchema("tenant1")).Find(&Book{}) // SELECT * FROM "tenant1"."books"
Example with model set manually:
type Book struct { ... } db.Model(&Book{}).Scopes(WithTenantSchema("tenant1")).Find(&Book{}) // model is set manually. // SELECT * FROM "tenant1"."books"
Example with destination set to a pointer to a struct:
type Book struct { ... } db.Scopes(WithTenantSchema("tenant1")).Find(&Book{}) // destination is set to a pointer to a struct. // SELECT * FROM "tenant1"."books"
Example with destination set to a pointer to an array/slice:
type Book struct { ... } db.Scopes(WithTenantSchema("tenant1")).Find(&[]Book{}) // destination is set to a pointer to an array/slice. // SELECT * FROM "tenant1"."books"
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.