Documentation ¶
Index ¶
- Variables
- func Close()
- func DropDB(dbName string, config Config) (err error)
- func Open(config Config) error
- func RW(permissionID int) (db *gorm.DB)
- func RegisterEnum(enum Enum)
- func RegisterExtension(extension string)
- func RegisterModel(model any)
- func UpdateComputedFieldsForModels(modelNames []string, pks []any) (err error)
- func Upsert(value Upsertable) (created bool, err error)
- type ComputedFieldsModel
- type Config
- type DBModel
- type Enum
- type RWConfig
- type Upsertable
Constants ¶
This section is empty.
Variables ¶
var DB *gorm.DB
Functions ¶
func Open ¶
Open and initialise the DB global variable and run AutoMigrate for all the registered models.
func RW ¶
RW returns a copy of DB with the appropriate gorm.Session and hooks applied so that the read/write permissions of the permission of the given ID will be reflected in any queries run using the returned gorm.DB. This is achieved by setting the DryRun flag in the gorm.Session/gorm.DB appropriately.
func RegisterEnum ¶
func RegisterEnum(enum Enum)
RegisterEnum will add the given enum to the enums global variable. The enums in this variable will be created at startup by createEnums.
func RegisterExtension ¶
func RegisterExtension(extension string)
RegisterExtension will add the given extension name to the extensions global variable. The extensions in this variable will be created at startup by createExtensions.
func RegisterModel ¶
func RegisterModel(model any)
RegisterModel will find the schema of the given model, wrap this information in a DBModel and add it to the models global mapping that will be passed to AutoMigrate when the DB connection is opened.
func UpdateComputedFieldsForModels ¶
UpdateComputedFieldsForModels will update the computed fields in all rows of the given model names.
func Upsert ¶
func Upsert(value Upsertable) (created bool, err error)
Upsert will upsert the given Upsertable value in the current DB.
Types ¶
type ComputedFieldsModel ¶
type ComputedFieldsModel interface { // UpdateComputedFields updates the computed fields for the instance of the ComputedFieldsModel. UpdateComputedFields(tx *gorm.DB) (err error) // Empty returns a pointer to an empty instance of the ComputedFieldsModel that can be used as the output for // gorm.DB.ScanRows for instance. Empty() any // Order returns the SQL expression that will be used for ordering the entire result set. This is used in // UpdateComputedFieldsForModels. Order() string }
ComputedFieldsModel represents a model that has computed fields that should be updated each time an instance of that model is created or updated. This does not cover fields that should only be computed solely on create or update.
type Config ¶
type Config interface { DBHost() string DBUser() string DBPassword() string DBName() string TestDBName() string DBPort() int DBSSLMode() string DBTimezone() string DBPostgresDBName() string DBDefaultRWAccess() (config RWConfig) DBRWAccessConfigForID(id int) (config RWConfig) DBRWAccessForID(id int) (read bool, write bool) DBPhaseReadAccess(id int) bool DBPhaseWriteAccess(id int) bool }
type DBModel ¶
func GetModel ¶
GetModel will return the DBModel from the models mapping that matches the type name of the given model.
func GetModelByName ¶
GetModelByName will return the DBModel from the models mapping that matches the given name. Remember that names should not be prefixed with their package name.
func (*DBModel) ColumnDBNames ¶
ColumnDBNames gets all the column names of the DBModel that are not the empty string.
func (*DBModel) ColumnDBNamesExcluding ¶
ColumnDBNamesExcluding gets all the column names of the DBModel that are not the empty string excluding the names given.
type Enum ¶
type Enum interface { fmt.Stringer driver.Valuer // Type returns the name of the type that should be created in the DB. Type() string // Values returns the possible values of the enum. Values() []string }
Enum represents an enum type that should be created on migration
type Upsertable ¶
type Upsertable interface { OnConflict() clause.OnConflict OnCreateOmit() []string }