pgdb

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEmptyBatch

func NewEmptyBatch() database.Batch

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.

func (*PgRowScan) Scan

func (p *PgRowScan) Scan(dest ...any) error

Scan - fill the dest with the given row columns.

type PgxBatch

type PgxBatch struct {
	// contains filtered or unexported fields
}

PgxBatch - Postgres Transaction Batch manager.

func (*PgxBatch) GetBatch

func (ptb *PgxBatch) GetBatch() any

func (*PgxBatch) Len

func (ptb *PgxBatch) Len() int

func (*PgxBatch) Queue

func (ptb *PgxBatch) Queue(query string, arguments ...any)

type PostgresDB

type PostgresDB struct {
	// contains filtered or unexported fields
}

PostgresDB - db manager.

func (*PostgresDB) AcquireDistributedLock

func (db *PostgresDB) AcquireDistributedLock(ctx context.Context, lockId int64) (int64, error)

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

func (t *PostgresTx) TxExec(ctx context.Context, execQuery string, args ...any) (int64, error)

TxExec - Execute a command query under a Transaction and return 1 or 0 if successful or failure.

func (*PostgresTx) TxExecBatch

func (t *PostgresTx) TxExecBatch(ctx context.Context, batch database.Batch) (int64, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL