Documentation ¶
Index ¶
- func MigrateSchemas(db *gorm.DB, logger *zap.Logger) error
- type CmplxTx
- type Db
- func (db *Db) ComparePasswords(hashedPwd string, plainPwd []byte) bool
- func (db *Db) CreateUser(ctx context.Context, user *models.User) (*models.UserORM, error)
- func (db *Db) DeleteUser(ctx context.Context, userID uint32) error
- func (db *Db) GetUser(ctx context.Context, userID uint32) (*models.UserORM, error)
- func (db *Db) GetUserIfExists(ctx context.Context, userID uint32, username, email string) (bool, *models.UserORM, error)
- func (db *Db) PerformComplexTransaction(transaction CmplxTx) (interface{}, error)
- func (db *Db) PerformTransaction(transaction Tx) error
- func (db *Db) UpdateUser(ctx context.Context, user *models.User) (*models.UserORM, error)
- func (db *Db) ValidateAndHashPassword(mdl models.IHashable) (string, error)
- type IDatabase
- type Tx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Db ¶
Db witholds connection to a postgres database as well as a logging handler
func (*Db) ComparePasswords ¶
ComparePasswords compares a hashed password and a plaintext password and returns a boolean stating wether they are equal or not
func (*Db) CreateUser ¶
CreateUser creates a user record in the backend database
func (*Db) DeleteUser ¶
DeleteUser deletes a user account from the backend database
func (*Db) GetUserIfExists ¶
func (db *Db) GetUserIfExists(ctx context.Context, userID uint32, username, email string) (bool, *models.UserORM, error)
GetUserIfExists checks that a given user exists based on user id
func (*Db) PerformComplexTransaction ¶
PerformComplexTransaction takes as input an anonymous function witholding logic to perform within a transaction returning an abstract type. This function is then invoked within a transaction and depending on the occurrence of any specific errors, the transaction is either committed to the database or completely rolled back. This returns the result obtained from the invocation of the anonymous function as well as any error occuring throughout the transaction lifecycle.
func (*Db) PerformTransaction ¶
PerformTransaction takes as input an anonymous function witholding logic to perform within a transaction. This function is then invoked within a transaction. if unsuccessful or any error is raised throughout the transaction, then, the transaction is rolled back. Returned is any error occuring throughout the transaction lifecycle
func (*Db) UpdateUser ¶
UpdateUser updates a user account in the database
type IDatabase ¶
type IDatabase interface { CreateUser(ctx context.Context, user *models.User) (*models.UserORM, error) UpdateUser(ctx context.Context, user *models.User) (*models.UserORM, error) DeleteUser(ctx context.Context, userID uint32) error GetUser(ctx context.Context, userID uint32) (*models.UserORM, error) GetUserIfExists(ctx context.Context, userID uint32, username, email string) (bool, *models.UserORM, error) ValidateAndHashPassword(mdl models.IHashable) (string, error) ComparePasswords(hashedPwd string, plainPwd []byte) bool // contains filtered or unexported methods }
IDatabase provides an interface which any database tied to this service should implement