Documentation ¶
Index ¶
- Constants
- Variables
- func IsErrNotFound(err error) bool
- func NewDBConnection(dbDriver, dsn string, dbPoolMax int, printQueriesToStdout bool) *bun.DB
- type DBHelper
- func (helper *DBHelper) Close() error
- func (helper *DBHelper) DeleteByColumn(ctx context.Context, modelsPtr, colName string, colValue any) error
- func (helper *DBHelper) DeleteByPKey(ctx context.Context, modelsPtr any) error
- func (helper *DBHelper) FindByColumn(ctx context.Context, modelsPtr any, columnName string, columnValue any) error
- func (helper *DBHelper) FindByPKey(ctx context.Context, modelsPtr any) error
- func (helper *DBHelper) Insert(ctx context.Context, modelsPtr any, ignoreDupicates bool) error
- func (helper *DBHelper) ListAll(ctx context.Context, modelsPtr any) error
- func (helper *DBHelper) ListByColumn(ctx context.Context, modelsPtr any, columnName string, columnValue any) error
- func (helper *DBHelper) Migrate(ctx context.Context, modelsPtr ...any) error
- func (helper *DBHelper) NewWithTx(tx bun.Tx) IDBHelper
- func (helper *DBHelper) Transactional(ctx context.Context, fn func(ctx context.Context, tx bun.Tx) error) error
- func (helper *DBHelper) UpdateByPKey(ctx context.Context, modelsPtr any) error
- func (helper *DBHelper) UpsertByPKey(ctx context.Context, modelsPtr any) error
- type GoCache
- func (s *GoCache) Clear(ctx context.Context) error
- func (s *GoCache) Close() error
- func (s *GoCache) Del(ctx context.Context, key string) error
- func (s *GoCache) Get(ctx context.Context, key string, dest any) error
- func (s *GoCache) Has(ctx context.Context, key string) bool
- func (s *GoCache) Marshal(v any) ([]byte, error)
- func (s *GoCache) Set(ctx context.Context, key string, val any, ttl time.Duration) error
- func (s *GoCache) Unmarshal(data []byte, vPtr any) error
- type ICache
- type IDBHelper
- type OrmDB
- type OrmDbTx
- type Rueidis
- func (s *Rueidis) Clear(ctx context.Context) error
- func (s *Rueidis) Close() error
- func (s *Rueidis) Del(ctx context.Context, key string) error
- func (s *Rueidis) Get(ctx context.Context, key string, dest any) error
- func (s *Rueidis) Has(ctx context.Context, key string) bool
- func (s *Rueidis) Marshal(v any) ([]byte, error)
- func (s *Rueidis) Set(ctx context.Context, key string, val any, ttl time.Duration) error
- func (s *Rueidis) Unmarshal(data []byte, vPtr any) error
Constants ¶
View Source
const ( // Postgresql driver DriverPostgresql = "pg" // SQlite driver DriverSqlite = sqliteshim.ShimName )
Variables ¶
View Source
var (
ErrNotFoundGoCache = errors.New("item not found")
)
Functions ¶
func IsErrNotFound ¶
IsErrNotFound checks if the error returned from any of the datastore library used here e.g redis, database etc is an error not found type
Types ¶
type DBHelper ¶
type DBHelper struct {
// contains filtered or unexported fields
}
func NewDBHelper ¶
func (*DBHelper) DeleteByColumn ¶
func (*DBHelper) DeleteByPKey ¶
func (*DBHelper) FindByColumn ¶
func (*DBHelper) FindByPKey ¶
func (*DBHelper) ListByColumn ¶
func (*DBHelper) NewWithTx ¶
NewWithTx returns a clone of DBHelper, HOWEVER OVERRIDING the dbConnection with a db-Transaction conn as the new dbConnection
func (*DBHelper) Transactional ¶
func (helper *DBHelper) Transactional(ctx context.Context, fn func(ctx context.Context, tx bun.Tx) error) error
Transactional simplifies transactions code, by automatically: starting a transaction, rolling back the transaction if an error is encountered & finally commiting the transaction if no error.
func Example_transactionUsage(ctx context.Context) { var example IDBHelper = nil example.Transactional( ctx, func(ctx context.Context, tx bun.Tx) error { example.NewWithTx(tx).FindByPKey(ctx, nil) example.NewWithTx(tx).UpdateByPKey(ctx, nil) return nil }, ) }
func (*DBHelper) UpdateByPKey ¶
type GoCache ¶
type GoCache struct {
// contains filtered or unexported fields
}
func NewGoCache ¶
func NewGoCache() *GoCache
type ICache ¶
type ICache interface { // Has checks to see if a key exists in the cache Has(ctx context.Context, key string) bool // Get gets a key from the cache Get(ctx context.Context, key string, dest any) error // Set sets a key to the cache Set(ctx context.Context, key string, val any, ttl time.Duration) error // Del deletes a key from the cache Del(ctx context.Context, key string) error // Clear used to flush/clear the cache Clear(ctx context.Context) error // Close closes the connection Close() error }
ICache is an interface that guides & ensure the use of different external cache library, in a way thats easy to swap.
type IDBHelper ¶
type IDBHelper interface { // Close: closes the connection Close() error // Migration create ONE OR MORE tables ONLY when they dont exists. Migrate(ctx context.Context, modelsPtr ...any) error // UpdateByPKey updates ONE OR MORE record by their primary-key (set in struct) UpdateByPKey(ctx context.Context, modelsPtr any) error // UpsertByPKey updates ONE OR MORE record by their primary-key and if the record // doesn't exist, it inserts it. UpsertByPKey(ctx context.Context, modelsPtr any) error // Insert inserts ONE OR MORE record. Insert(ctx context.Context, modelsPtr any, ignoreDupicates bool) error // FindByPKey gets ONE record by primary-key (set in struct). [limit 1] FindByPKey(ctx context.Context, modelsPtr any) error // FindByColumn gets a record via supplied column-name & column-value. [limit 1] FindByColumn(ctx context.Context, modelsPtr any, columnName string, columnValue any) error // List all records of a table. Useful for loading settings from db ListAll(ctx context.Context, modelsPtr any) error // List records of a table via supplied column and column value ListByColumn(ctx context.Context, modelsPtr any, columnName string, columnValue any) error // DeleteByPKey deletes a record using primary key in struct DeleteByPKey(ctx context.Context, modelsPtr any) error // DeleteByColumn deletes ONE OR MORE record via supplied column-name & column-value DeleteByColumn(ctx context.Context, modelsPtr, columnName string, columnValue any) error // NewWithTx returns a clone of DBHelper, HOWEVER OVERRIDING the dbConnection with a db-Transaction conn // as the new dbConnection NewWithTx(tx bun.Tx) IDBHelper // Transactional simplifies transactions code, by automatically: // // starting a transaction, rolling back the transaction if an error // is encountered & finally commiting the transaction if no error. // func Example_transactionUsage(ctx context.Context) { // var example IDBHelper = nil // example.Transactional( // ctx, // func(ctx context.Context, tx bun.Tx) error { // example.NewWithTx(tx).FindByPKey(ctx, nil) // example.NewWithTx(tx).UpdateByPKey(ctx, nil) // return nil // }, // ) // } Transactional(ctx context.Context, fn func(ctx context.Context, tx bun.Tx) error) error }
IDBHelper is an interface that provides quick helpers for handling database operations
Click to show internal directories.
Click to hide internal directories.