Documentation ¶
Overview ¶
Package database witholds database specific utilities for the core database libary This package mainly deals with interactions with the postgresql database.
Index ¶
- func Connect(connectionString, databaseType string) (*gorm.DB, error)
- func DeleteCreatedEntities(db *gorm.DB) func()
- func GenerateRandomString(n int) string
- type CmplxTx
- type DatabaseConn
- func (db *DatabaseConn) ComparePasswords(hashedPwd string, plainPwd []byte) bool
- func (db *DatabaseConn) PerformComplexTransaction(ctx context.Context, transaction CmplxTx) (interface{}, error)
- func (db *DatabaseConn) PerformTransaction(ctx context.Context, transaction Tx) error
- func (db *DatabaseConn) ValidateAndHashPassword(password string) (string, error)
- type Tx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteCreatedEntities ¶
DeleteCreatedEntities sets up GORM `onCreate` hook and return a function that can be deferred to remove all the entities created after the hook was set up You can use it as
func TestSomething(t *testing.T){ db, _ := gorm.Open(...) cleaner := DeleteCreatedEntities(db) defer cleaner()
}
func GenerateRandomString ¶
GenerateRandomString generates a random string based on the size specified by the client
Types ¶
type DatabaseConn ¶
func NewDatabaseConn ¶
func NewDatabaseConn(connString, databaseType string) *DatabaseConn
NewDatabaseConn obtains a reference to a database connection object
func (*DatabaseConn) ComparePasswords ¶
func (db *DatabaseConn) ComparePasswords(hashedPwd string, plainPwd []byte) bool
ComparePasswords compares a hashed password and a plaintext password and returns a boolean stating wether they are equal or not
func (*DatabaseConn) PerformComplexTransaction ¶
func (db *DatabaseConn) PerformComplexTransaction(ctx context.Context, transaction CmplxTx) (interface{}, error)
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 (*DatabaseConn) PerformTransaction ¶
func (db *DatabaseConn) PerformTransaction(ctx context.Context, transaction Tx) error
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 (*DatabaseConn) ValidateAndHashPassword ¶
func (db *DatabaseConn) ValidateAndHashPassword(password string) (string, error)
ValidateAndHashPassword validates, hashes and salts a password