pgx

package module
v0.0.0-...-a8d9c21 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsWithinTransaction

func IsWithinTransaction(ctx context.Context) bool

func NewFakeTransactor

func NewFakeTransactor(db *pgx.Conn) (FakeTransactor, DBGetter)

NewFakeTransactor initializes a Transactor and DBGetter that do nothing: - the Transactor just executes its callback and returns the error, - the DBGetter just returns the DB handler. They can be used in tests where the transaction system itself doesn't need to be tested.

func NewFakeTransactorFromPool

func NewFakeTransactorFromPool(db *pgxpool.Pool) (FakeTransactor, DBGetter)

NewFakeTransactorFromPool initializes a Transactor and DBGetter that do nothing: - the Transactor just executes its callback and returns the error, - the DBGetter just returns the DB handler. They can be used in tests where the transaction system itself doesn't need to be tested.

func NewTransactor

func NewTransactor(db *pgx.Conn) (*Transactor, DBGetter)

func NewTransactorFromPool

func NewTransactorFromPool(pool *pgxpool.Pool) (*Transactor, DBGetter)

Types

type DB

type DB interface {
	Exec(ctx context.Context, sql string, arguments ...any) (commandTag pgconn.CommandTag, err error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row

	CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
	SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
}

DB is the common interface between *pgx.Conn, *pgx.Tx, *pgxpool.Conn, *pgxpool.Pool and *pgxpool.Tx.

type DBGetter

type DBGetter func(context.Context) DB

DBGetter is used to get the current DB handler from the context. It returns the current transaction if there is one, otherwise it will return the original DB.

type FakeTransactor

type FakeTransactor struct{}

func (FakeTransactor) WithinTransaction

func (FakeTransactor) WithinTransaction(ctx context.Context, txFunc func(context.Context) error) error

type Transactor

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

func (*Transactor) WithinTransaction

func (t *Transactor) WithinTransaction(ctx context.Context, txFunc func(context.Context) error) error

Jump to

Keyboard shortcuts

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