txutil

package
v1.119.11 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package txutil provides safe transaction-encapsulation functions which have retry semantics as necessary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInsideTx added in v1.108.1

func IsInsideTx(ctx context.Context) bool

IsInsideTx returns whether ctx is from a WithTx call.

func WithTx

func WithTx(ctx context.Context, db tagsql.DB, txOpts *sql.TxOptions, fn func(context.Context, tagsql.Tx) error) (err error)

WithTx starts a transaction on the given sql.DB. The transaction is started in the appropriate manner, and will be restarted if appropriate. While in the transaction, fn is called with a handle to the transaction in order to make use of it. If fn returns an error, the transaction is rolled back. If fn returns nil, the transaction is committed.

If fn has any side effects outside of changes to the database, they must be idempotent! fn may be called more than one time.

Types

This section is empty.

Jump to

Keyboard shortcuts

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