tx

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(
	ctx context.Context,
	trm Trm,
	level pgx.TxIsoLevel,
	fn func(ctx context.Context) error,
	opts ...settings.Opt,
) error

func DoAndRet

func DoAndRet[T any](
	ctx context.Context,
	mgr Trm,
	level pgx.TxIsoLevel,
	f func(ctx context.Context) (T, error),
	opts ...settings.Opt,
) (ret T, err error)

func DoReadCommitted

func DoReadCommitted(
	ctx context.Context,
	manager Trm,
	fn func(ctx context.Context) error,
	opts ...settings.Opt,
) error

func DoReadCommittedRet

func DoReadCommittedRet[T any](
	ctx context.Context,
	manager Trm,
	f func(ctx context.Context) (T, error),
	opts ...settings.Opt,
) (ret T, err error)

func DoReadUncommitted

func DoReadUncommitted(
	ctx context.Context,
	manager Trm,
	fn func(ctx context.Context) error,
	opts ...settings.Opt,
) error

func DoReadUncommittedRet

func DoReadUncommittedRet[T any](
	ctx context.Context,
	manager Trm,
	f func(ctx context.Context) (T, error),
	opts ...settings.Opt,
) (ret T, err error)

func DoRepeatableRead

func DoRepeatableRead(
	ctx context.Context,
	manager Trm,
	fn func(ctx context.Context) error,
	opts ...settings.Opt,
) error

func DoRepeatableReadRet

func DoRepeatableReadRet[T any](
	ctx context.Context,
	manager Trm,
	f func(ctx context.Context) (T, error),
	opts ...settings.Opt,
) (ret T, err error)

func DoSerializable

func DoSerializable(
	ctx context.Context,
	manager Trm,
	fn func(ctx context.Context) error,
	opts ...settings.Opt,
) error

func DoSerializableRet

func DoSerializableRet[T any](
	ctx context.Context,
	manager Trm,
	f func(ctx context.Context) (T, error),
	opts ...settings.Opt,
) (ret T, err error)

func DoSettings

func DoSettings(
	ctx context.Context,
	trm Trm,
	settings *trmpgx.Settings,
	fn func(ctx context.Context) error,
) error

func NewSettings

func NewSettings(level pgx.TxIsoLevel, opts ...settings.Opt) *trmpgx.Settings

func ReadCommitted

func ReadCommitted(opts ...settings.Opt) *trmpgx.Settings

func ReadUncommitted

func ReadUncommitted(opts ...settings.Opt) *trmpgx.Settings

func RepeatableRead

func RepeatableRead(opts ...settings.Opt) *trmpgx.Settings

func Serializable

func Serializable(opts ...settings.Opt) *trmpgx.Settings

Types

type DB

type DB interface {
	// Exec executes the given SQL statement with the provided arguments in the context of the executor.
	//
	// Parameters:
	// - ctx: The context.Context object.
	// - sql: The SQL statement to execute.
	// - arguments: The arguments to be passed to the SQL statement.
	//
	// Returns:
	// - pgconn.CommandTag: The command tag returned by the execution.
	// - error: An error if the execution fails.
	Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
	// Query executes a SQL query with the provided arguments in the context of the executor.
	//
	// Parameters:
	// - ctx: The context.Context object.
	// - sql: The SQL query to execute.
	// - arguments: The arguments to be passed to the SQL query.
	//
	// Returns:
	// - pgx.Rows: The result of the query.
	// - error: An error if the query execution fails.
	Query(ctx context.Context, sql string, arguments ...interface{}) (pgx.Rows, error)
	// QueryRow executes a SQL query with the provided arguments in the context of the executor,
	// returning a single row result.
	//
	// Parameters:
	// - ctx: The context.Context object.
	// - sql: The SQL query to execute.
	// - arguments: The arguments to be passed to the SQL query.
	//
	// Returns:
	// - pgx.Row: The result of the query as a single row.
	QueryRow(ctx context.Context, sql string, arguments ...interface{}) 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
}

func NewTxDb

func NewTxDb(defaultTr trmpgx.Tr, options ...DbOption) DB

NewTxDb creates a new TxExecutor with the given defaultTr and options.

Parameters: - defaultTr: The default transaction to use. - options: Optional configurations for the TxExecutor.

Returns: - *TxExecutor: The newly created TxExecutor.

type DbOption

type DbOption func(*executor)

func WithCtxGetter

func WithCtxGetter(ctxGetter ctxGetter) DbOption

WithCtxGetter sets the ctxGetter for the TxExecutor.

Parameters: - ctxGetter: The ctxGetter implementation to be used.

Returns: - TxExecutorOption: A function that takes a TxExecutor pointer and sets its ctxGetter field.

type Trm

type Trm = trm.Manager

Jump to

Keyboard shortcuts

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