txman

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractTxQueryKey

func ExtractTxQueryKey(ctx context.Context) (string, bool)

func InjectTX

func InjectTX(ctx context.Context, tx Tx) context.Context

func ReadCommitted

func ReadCommitted[T any](ctx context.Context, tm TxManager, h GenericHandler[T], opts ...TxOption) (T, error)

func RepeatableRead

func RepeatableRead[T any](ctx context.Context, tm TxManager, h GenericHandler[T], opts ...TxOption) (T, error)

func Serializable

func Serializable[T any](ctx context.Context, tm TxManager, h GenericHandler[T], opts ...TxOption) (T, error)

Types

type GenericHandler

type GenericHandler[T any] func(context.Context) (T, error)

type Handler

type Handler = func(context.Context) error

type Postgres

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

type Tx

type Tx interface {
	Commit(ctx context.Context) error
	Rollback(ctx context.Context) error
	Conn() *pgx.Conn
	CopyFrom(ctx context.Context, table pgx.Identifier, cols []string, src pgx.CopyFromSource) (int64, error)
	SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
	LargeObjects() pgx.LargeObjects
	Prepare(ctx context.Context, name, sql string) (*pgconn.StatementDescription, error)
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	Begin(ctx context.Context) (pgx.Tx, error)
}

func ExtractTX

func ExtractTX(ctx context.Context) (Tx, bool)

type TxConfig

type TxConfig struct {
	IsoLevel   pgx.TxIsoLevel
	Retry      uint
	ReadOnly   bool
	MaxBackoff time.Duration
}

type TxManager

type TxManager interface {
	ReadCommitted(ctx context.Context, h Handler, opts ...TxOption) error
	RepeatableRead(ctx context.Context, h Handler, opts ...TxOption) error
	Serializable(ctx context.Context, h Handler, opts ...TxOption) error
	RunWithOpts(ctx context.Context, h Handler, opts []TxOption) error
}

func New

func New(db Postgres) TxManager

type TxOption

type TxOption func(*TxConfig)

func ReadOnly

func ReadOnly(on bool) TxOption

func WithIso

func WithIso(lvl pgx.TxIsoLevel) TxOption

func WithMaxBackoff

func WithMaxBackoff(d time.Duration) TxOption

func WithRetry

func WithRetry(n uint) TxOption

Jump to

Keyboard shortcuts

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