Documentation ¶
Index ¶
- func NewEmptyBatch() database.Batch
- func SetupPostgresDB(ctx context.Context, dbConf database.ConnConfig, ...) database.InstanceManager
- type PgRowScan
- type PgxBatch
- type PostgresDB
- func (db *PostgresDB) AcquireDistributedLock(ctx context.Context, lockId int64) (int64, error)
- func (db *PostgresDB) CloseDbConnPool()
- func (db *PostgresDB) Exec(ctx context.Context, lockId int64, execQuery string, args ...any) (int64, error)
- func (db *PostgresDB) ExecTaskWithDistributedLock(ctx context.Context, lockId int64, task func(ctx context.Context) error) (err error)
- func (db *PostgresDB) ExecTransactionalTask(ctx context.Context, lockId int64, ...) error
- func (db *PostgresDB) GetConnFromPool(ctx context.Context) (any, error)
- func (db *PostgresDB) GetConnectionConfig() database.ConnConfig
- func (db *PostgresDB) GetDbConnPool() (any, error)
- func (db *PostgresDB) Query(ctx context.Context, lockId int64, query string, args ...any) (*database.ResultSet, error)
- func (db *PostgresDB) QueryAndProcess(ctx context.Context, lockId int64, ...) error
- func (db *PostgresDB) ReleaseDistributedLock(ctx context.Context, lockId int64) error
- func (db *PostgresDB) TxBegin(ctx context.Context, lockId int64) (pgxTx database.Transaction, err error)
- type PostgresTx
- func (t *PostgresTx) TxCommit(ctx context.Context, lockId int64) error
- func (t *PostgresTx) TxExec(ctx context.Context, execQuery string, args ...any) (int64, error)
- func (t *PostgresTx) TxExecBatch(ctx context.Context, batch database.Batch) (int64, error)
- func (t *PostgresTx) TxQuery(ctx context.Context, query string, args ...any) (*database.ResultSet, error)
- func (t *PostgresTx) TxRollback(ctx context.Context, lockId int64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewEmptyBatch ¶
func SetupPostgresDB ¶
func SetupPostgresDB(ctx context.Context, dbConf database.ConnConfig, preparesStatements ...database.PreparedStatement) database.InstanceManager
SetupPostgresDB - setup Postgres DB connection.
Types ¶
type PgRowScan ¶
type PgRowScan struct {
// contains filtered or unexported fields
}
PgRowScan - Wrapper around a row scanner.
type PgxBatch ¶
type PgxBatch struct {
// contains filtered or unexported fields
}
PgxBatch - Postgres Transaction Batch manager.
type PostgresDB ¶
type PostgresDB struct {
// contains filtered or unexported fields
}
PostgresDB - db manager.
func (*PostgresDB) AcquireDistributedLock ¶
AcquireDistributedLock acquire a distribuited lock with the given Id. It doesn't release the connection associated with the lockId, so it's important to release that when finishing the transaction. This is done by the method ReleaseDistributedLock
func (*PostgresDB) CloseDbConnPool ¶
func (db *PostgresDB) CloseDbConnPool()
CloseDbConnPool - close db connection pool.
func (*PostgresDB) Exec ¶
func (db *PostgresDB) Exec(ctx context.Context, lockId int64, execQuery string, args ...any) (int64, error)
Exec - execute a command query and return 1 or 0 if successful or failure. , If lockId = 0 it will get a connection from pool, otherwise will try to retrieve the connection associated with the given lockId In case of we get the lockId != 0 remember that the connection won't be released, because it belongs to the of the Distributed Lock Scope That needs to release it
func (*PostgresDB) ExecTaskWithDistributedLock ¶
func (db *PostgresDB) ExecTaskWithDistributedLock(ctx context.Context, lockId int64, task func(ctx context.Context) error) (err error)
ExecTaskWithDistributedLock - exec a task wrapped around a distributed lock. LockId is managed by the business logic and not autogenerated, so it needs to be passed as parameter
func (*PostgresDB) ExecTransactionalTask ¶
func (db *PostgresDB) ExecTransactionalTask(ctx context.Context, lockId int64, task func(ctx context.Context, pgTx database.Transaction) error) error
ExecTransactionalTask - execute a transactional task, and optionally using the distributed lock context (if previously created). If lockId = 0 it will not use distributed lock context
func (*PostgresDB) GetConnFromPool ¶
func (db *PostgresDB) GetConnFromPool(ctx context.Context) (any, error)
GetConnFromPool - get a connection from the pool.
func (*PostgresDB) GetConnectionConfig ¶
func (db *PostgresDB) GetConnectionConfig() database.ConnConfig
GetConnectionConfig - get Db Connection config.
func (*PostgresDB) GetDbConnPool ¶
func (db *PostgresDB) GetDbConnPool() (any, error)
GetDbConnPool - get the connection pool.
func (*PostgresDB) Query ¶
func (db *PostgresDB) Query(ctx context.Context, lockId int64, query string, args ...any) (*database.ResultSet, error)
Query - Execute a query and return a *ResultSet and Error, If lockId = 0 it will get a connection from pool, otherwise will try to retrieve the connection associated with the given lockId In case of we get the lockId != 0 remember that the connection won't be released, because it belongs to the of the Distributed Lock Scope That needs to release it
func (*PostgresDB) QueryAndProcess ¶
func (db *PostgresDB) QueryAndProcess(ctx context.Context, lockId int64, processCallback func(row database.Row) error, query string, args ...any) error
QueryAndProcess - Execute a query and apply the function processCallback to every row instead of returning the entire result set in memory. If lockId = 0 it will get a connection from pool, otherwise will try to retrieve the connection associated with the given lockId In case of we get the lockId != 0 remember that the connection won't be released, because it belongs to the of the Distributed Lock Scope That needs to release it
func (*PostgresDB) ReleaseDistributedLock ¶
func (db *PostgresDB) ReleaseDistributedLock(ctx context.Context, lockId int64) error
func (*PostgresDB) TxBegin ¶
func (db *PostgresDB) TxBegin(ctx context.Context, lockId int64) (pgxTx database.Transaction, err error)
TxBegin - Begin a Transaction and return Transaction. If lockId = 0 it will get a connection from pool, otherwise will try to retrieve the connection associated with the given lockId In case of we get the lockId != 0 remember that the connection won't be released, because it belongs to the of the Distributed Lock Scope That needs to release it
type PostgresTx ¶
type PostgresTx struct {
// contains filtered or unexported fields
}
PostgresTx - Postgres Transaction manager.
func (*PostgresTx) TxCommit ¶
func (t *PostgresTx) TxCommit(ctx context.Context, lockId int64) error
TxCommit - Commit a transaction and release the connection to the pool.
func (*PostgresTx) TxExec ¶
TxExec - Execute a command query under a Transaction and return 1 or 0 if successful or failure.
func (*PostgresTx) TxExecBatch ¶
TxExecBatch - Execute batch query in single transaction.
func (*PostgresTx) TxQuery ¶
func (t *PostgresTx) TxQuery(ctx context.Context, query string, args ...any) (*database.ResultSet, error)
TxQuery - Execute a query under a Transaction and return a *ResultSet and Error.
func (*PostgresTx) TxRollback ¶
func (t *PostgresTx) TxRollback(ctx context.Context, lockId int64)
TxRollback - Rollback a transaction and release the connection to the pool.