dbutil

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MPL-2.0 Imports: 7 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RollbackWithoutCancel added in v0.27.0

func RollbackWithoutCancel[TExec riverdriver.ExecutorTx](ctx context.Context, execTx TExec) error

RollbackWithoutCancel initiates a rollback, but one in which context is overridden with context.WithoutCancel so that the rollback can proceed even if a previous operation was cancelled. This decreases the chance that a transaction is accidentally left open and in an ambiguous state.

A rollback error is returned the same way most driver rollbacks return an error, but given this is normally expected to be used in a defer statement, it's unusual for the error to be handled.

func SafeIdentifier added in v0.32.0

func SafeIdentifier(ident string) string

SafeIdentifier returns a safely quoted identifier (e.g. a table or schem name) for use in SQL queries. It wraps the identifier in quotes and escapes any internal quotes as appropriate.

func WithTx

func WithTx[TExec riverdriver.Executor](ctx context.Context, exec TExec, innerFunc func(ctx context.Context, execTx riverdriver.ExecutorTx) error) error

WithTx runs the given function in a transaction, reusing exec if it's already a transaction. Only a transaction started by WithTx is committed or rolled back; the owner of a reused transaction must roll it back on error. RIVER_USE_LEGACY_SUBTRANSACTIONS restores savepoints as described in WithTxV.

Rollbacks use RollbackWithoutCancel to maximize the chance of a successful rollback even where an operation within the transaction timed out due to context timeout.

func WithTxV

func WithTxV[TExec riverdriver.Executor, T any](ctx context.Context, exec TExec, innerFunc func(ctx context.Context, execTx riverdriver.ExecutorTx) (T, error)) (T, error)

WithTxV runs the given function in a transaction, allowing the return of a generic value. If exec is already a transaction, it is reused without starting a savepoint, committing, or rolling back. On error, the owner must roll back that transaction, including any partial writes made by innerFunc. Call Begin explicitly when an operation needs its own rollback boundary.

As a temporary compatibility fallback, setting RIVER_USE_LEGACY_SUBTRANSACTIONS=1 (or true) disables transaction reuse and restores savepoints. This fallback is planned for removal in a future release.

Rollbacks use RollbackWithoutCancel to maximize the chance of a successful rollback even where an operation within the transaction timed out due to context timeout.

Types

This section is empty.

Jump to

Keyboard shortcuts

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