pgxv4

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package pgxv4 is an implementation of trm.Transaction interface by Transaction for pgx.Tx.

Index

Constants

This section is empty.

Variables

DefaultCtxGetter is the CtxGetter with settings.DefaultCtxKey.

Functions

func NewDefaultFactory

func NewDefaultFactory(db Transactional) trm.TrFactory

NewDefaultFactory creates default trm.Transaction(pgx.Tx).

func NewFactory

func NewFactory(db Transactional) trm.TrFactory

NewFactory creates trm.Transaction(pgx.Tx).

Types

type CtxGetter

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

CtxGetter gets Tr from trm.СtxManager by casting trm.Transaction to Tr.

func NewCtxGetter

func NewCtxGetter(c trm.СtxManager) *CtxGetter

NewCtxGetter returns *CtxGetter to get Tr from context.Context.

func (*CtxGetter) DefaultTrOrDB

func (c *CtxGetter) DefaultTrOrDB(ctx context.Context, db Tr) Tr

DefaultTrOrDB returns Tr from context.Context or DB(Tr) otherwise.

func (*CtxGetter) TrOrDB

func (c *CtxGetter) TrOrDB(ctx context.Context, key trm.CtxKey, db Tr) Tr

TrOrDB returns Tr from context.Context by trm.CtxKey or DB(Tr) otherwise.

type Opt

type Opt func(*Settings) error

Opt is a type to configure Settings.

func WithTxOptions

func WithTxOptions(opts pgx.TxOptions) Opt

WithTxOptions sets up pgx.TxOptions for the Settings.

type Settings

type Settings struct {
	trm.Settings
	// contains filtered or unexported fields
}

Settings contains settings for pgxv4.Transaction.

func MustSettings

func MustSettings(trms trm.Settings, oo ...Opt) Settings

MustSettings returns Settings if err is nil and panics otherwise.

func NewSettings

func NewSettings(trms trm.Settings, oo ...Opt) (Settings, error)

NewSettings creates Settings.

func (Settings) EnrichBy

func (s Settings) EnrichBy(in trm.Settings) trm.Settings

EnrichBy fills nil properties from external Settings.

func (Settings) TxOpts

func (s Settings) TxOpts() pgx.TxOptions

TxOpts returns trm.CtxKey for the trm.Transaction.

type Tr

type Tr interface {
	Begin(ctx context.Context) (pgx.Tx, error)
	BeginFunc(ctx context.Context, f func(pgx.Tx) error) (err error)

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

	Exec(ctx context.Context, sql string, arguments ...interface{}) (commandTag pgconn.CommandTag, err error)
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
	QueryFunc(ctx context.Context, sql string, args []interface{}, scans []interface{}, f func(pgx.QueryFuncRow) error) (pgconn.CommandTag, error)
}

Tr is an interface to work with pgx.Conn, pgxpool.Conn or pgxpool.Pool StmtContext and Stmt are not implemented!

type Transaction

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

Transaction is trm.Transaction for pgx.Tx.

func NewTransaction

func NewTransaction(
	ctx context.Context,
	opts pgx.TxOptions,
	db Transactional,
) (context.Context, *Transaction, error)

NewTransaction creates trm.Transaction for pgx.Tx.

func (*Transaction) Begin

func (t *Transaction) Begin(ctx context.Context, _ trm.Settings) (context.Context, trm.Transaction, error)

Begin nested transaction by save point.

func (*Transaction) Closed

func (t *Transaction) Closed() <-chan struct{}

Closed returns a channel that's closed when transaction committed or rolled back.

func (*Transaction) Commit

func (t *Transaction) Commit(ctx context.Context) error

Commit the trm.Transaction.

func (*Transaction) IsActive

func (t *Transaction) IsActive() bool

IsActive returns true if the transaction started but not committed or rolled back.

func (*Transaction) Rollback

func (t *Transaction) Rollback(ctx context.Context) error

Rollback the trm.Transaction.

func (*Transaction) Transaction

func (t *Transaction) Transaction() interface{}

Transaction returns the real transaction pgx.Tx.

type Transactional

type Transactional interface {
	BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
}

Transactional is an interface to work with pgx.Conn, pgxpool.Conn or pgxpool.Pool.

Jump to

Keyboard shortcuts

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