db

package
v0.0.0-...-ea5f57a Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProvidePgConnectionPool

func ProvidePgConnectionPool() (*pgxpool.Pool, error)

Types

type Database

type Database struct {
	Conn *pgxpool.Pool
}

func ProvideNewDatabase

func ProvideNewDatabase(pool *pgxpool.Pool) (*Database, error)

func ProvideNewDatabaseConnection

func ProvideNewDatabaseConnection(pgpool *pgxpool.Pool) *Database

func (*Database) ExtractTx

func (db *Database) ExtractTx(ctx context.Context) pgx.Tx

extractTx extracts transaction from context and creates a new tx if it doesn't exist.

func (*Database) ExtractTxWithError

func (db *Database) ExtractTxWithError(ctx context.Context) (pgx.Tx, error)

func (*Database) ExtractTxWithoutError

func (db *Database) ExtractTxWithoutError(ctx context.Context) pgx.Tx

func (*Database) GetExistingOrNewTransaction

func (db *Database) GetExistingOrNewTransaction(ctx context.Context) (pgx.Tx, error)

func (*Database) Query

func (db *Database) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)

func (*Database) QueryRow

func (db *Database) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row

func (*Database) WithinTransaction

func (db *Database) WithinTransaction(ctx context.Context, tFunc func(ctx context.Context) error) error

WithinTransaction runs function within transaction

The transaction commits when function were finished without error

type TransactionManager

type TransactionManager interface {
	// WithinTransaction runs a function within a database transaction.
	//
	// Transaction is propagated in the context,
	// so it is important to propagate it to underlying repositories.
	// Function commits if error is nil, and rollbacks if not.
	// It returns the same error.
	WithinTransaction(context.Context, func(ctx context.Context) error) error
}

TransactionManager runs logic inside a single database transaction

func ProvideNewPostgresTransactor

func ProvideNewPostgresTransactor(db *Database) (TransactionManager, error)

Jump to

Keyboard shortcuts

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