transaction

package
v1.0.0-beta.230 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run[R any](ctx context.Context, creator Creator, cb func(ctx context.Context) (R, error)) (R, error)

Runs the callback inside a transaction

func RunInNewTransaction

func RunInNewTransaction[R any](ctx context.Context, creator Creator, cb func(ctx context.Context) (R, error)) (R, error)

RunInNewTransaction starts and commits a transaction independently of any transaction in ctx. For Ent-backed adapters, it acquires a separate database connection and shadows the caller's transaction in the callback.

WARNING: The callback's writes are not atomic with the caller. They remain committed if the caller later rolls back, and the callback cannot observe the caller's uncommitted writes. Calling this while the caller holds locks needed by the callback can deadlock. Concurrent use can also exhaust the connection pool because an operation may hold one connection while acquiring another.

Use only when the domain explicitly requires a durable side effect outside the caller's transaction and the visibility, locking, and connection-pool risks have been reviewed.

func RunWithNoValue

func RunWithNoValue(ctx context.Context, creator Creator, cb func(ctx context.Context) error) error

RunWithNoValue the callback inside a transaction with no return value

func SetDriverOnContext

func SetDriverOnContext(ctx context.Context, tx Driver) (context.Context, error)

Types

type Creator

type Creator interface {
	Tx(ctx context.Context) (context.Context, Driver, error)
}

Able to start a new transaction

type Driver

type Driver interface {
	Commit() error
	Rollback() error
	SavePoint() error
}

Driver is an interface for transaction drivers

func GetDriverFromContext

func GetDriverFromContext(ctx context.Context) (Driver, error)

type DriverConflictError

type DriverConflictError struct{}

func (*DriverConflictError) Error

func (e *DriverConflictError) Error() string

type DriverNotFoundError

type DriverNotFoundError struct{}

func (*DriverNotFoundError) Error

func (e *DriverNotFoundError) Error() string

Jump to

Keyboard shortcuts

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