txn

package
v0.3.85 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Func

func Func(
	ctx context.Context,
	logger *slog.Logger,
	provider Provider,
	fn func(Datastore) error,
) error

Func executes the given function within a transaction, automatically committing or rolling back the transaction as necessary.

func Value

func Value[T any](
	ctx context.Context,
	logger *slog.Logger,
	provider Provider,
	fn func(Datastore) (T, error),
) (T, error)

Value executes the given function within a transaction, automatically committing or rolling back the transaction as necessary. It returns the non-error value returned by fn on success.

func Values

func Values[T1, T2 any](
	ctx context.Context,
	logger *slog.Logger,
	provider Provider,
	fn func(Datastore) (T1, T2, error),
) (T1, T2, error)

Values executes the given function within a transaction, automatically committing or rolling back the transaction as necessary. It returns the non-error values returned by fn on success.

Types

type CommitFn

type CommitFn func() error

CommitFn commits a transaction.

type Datastore

type Datastore interface {
	repositories.AuditEvent
	repositories.Resource
}

Datastore is a unified interface for repositories.

type Provider

type Provider interface {
	Datastore() Datastore
	BeginTx(context.Context) (Datastore, CommitFn, RollbackFn, error)
}

Provider provides access to either a transactional or non-transactional database.

type RollbackFn

type RollbackFn func() error

RollbackFn rolls back a transaction. No error should be produced for a committed transaction.

Jump to

Keyboard shortcuts

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