Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetSchemaNameFromDb ¶
GetSchemaNameFromDb retrieves the schema name from the given gorm.DB transaction. It first checks if the table expression is not nil, then extracts the schema name from the table expression SQL. If the schema name is empty, it returns an error.
It is intended to be used in a gorm hook, such as BeforeCreate, BeforeUpdate, etc.
Example:
type User struct {
gorm.Model
Username string
}
func (User) TableName() string {
return "domain1.mock_private"
}
func (User) BeforeCreate(tx *gorm.DB) (err error) {
schemaName, err := postgres.GetSchemaNameFromDb(tx) // schemaName = "domain1"
if err != nil {
return err
}
// ... do something with schemaName
return nil
}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.