Documentation ¶
Overview ¶
Package pgxv4 is an implementation of trm.Transaction interface by Transaction for pgx.Tx.
Index ¶
- Variables
- func NewDefaultFactory(db Transactional) trm.TrFactory
- func NewFactory(db Transactional) trm.TrFactory
- type CtxGetter
- type Opt
- type Settings
- type Tr
- type Transaction
- func (t *Transaction) Begin(ctx context.Context, _ trm.Settings) (context.Context, trm.Transaction, error)
- func (t *Transaction) Closed() <-chan struct{}
- func (t *Transaction) Commit(ctx context.Context) error
- func (t *Transaction) IsActive() bool
- func (t *Transaction) Rollback(ctx context.Context) error
- func (t *Transaction) Transaction() interface{}
- type Transactional
Constants ¶
This section is empty.
Variables ¶
var DefaultCtxGetter = NewCtxGetter(trmcontext.DefaultManager)
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 ¶
DefaultTrOrDB returns Tr from context.Context or DB(Tr) otherwise.
type Opt ¶
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 ¶
MustSettings returns Settings if err is nil and panics otherwise.
func NewSettings ¶
NewSettings creates Settings.
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.