tx

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

func FromContext[T any](ctx context.Context) T

func ToContext

func ToContext[T any](parent context.Context, value T) context.Context

Types

type Context

type Context interface {
	Transaction() Transaction
	Parent() Context
	Resources() any
}

func NewContext

func NewContext() Context

type Executor

type Executor interface {
	Execute(ctx context.Context, fn Func) (any, error)
	ExecutorInTransaction(ctx context.Context, fn Func, options ...Option) (any, error)
	TransactionManager() Manager
}

func NewExecutor

func NewExecutor(manager Manager, options ...Option) Executor

type Func

type Func func(ctx context.Context, template Template) (any, error)

type IsolationLevel

type IsolationLevel int
const (
	LevelDefault IsolationLevel = iota
	LevelReadUncommitted
	LevelReadCommitted
	LevelWriteCommitted
	LevelRepeatableRead
	LevelSnapshot
	LevelSerializable
	LevelLinearizable
)

type Manager

type Manager interface {
	CreateContext() Context
	Connection() *sql.DB
	GetOrCreateTransaction(ctx context.Context, options ...Option) (Transaction, error)
	Commit(ctx context.Context, tx Transaction) error
	Rollback(ctx context.Context, tx Transaction) error
}

func NewManager

func NewManager(db *sql.DB, options ...Option) Manager

type Option

type Option func(options *Options)

func WithIsolation

func WithIsolation(isolationLevel IsolationLevel) Option

func WithPropagation

func WithPropagation(propagation Propagation) Option

func WithReadOnly

func WithReadOnly(readOnly bool) Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

type Options

type Options struct {
	Propagation    Propagation
	Timeout        time.Duration
	ReadOnly       bool
	IsolationLevel IsolationLevel
}

func DefaultOptions

func DefaultOptions() *Options

func NewOptions

func NewOptions(opts ...Option) *Options

func WithOptions

func WithOptions(opts *Options, options ...Option) *Options

type Propagation

type Propagation int
const (
	PropagationRequired Propagation = iota
	PropagationSupports
	PropagationMandatory
	PropagationNever
	PropagationNotSupported
	PropagationNested
	PropagationRequiredNew
)

type Template

type Template interface {
	Exec(query string, args ...any) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	Prepare(query string) (*sql.Stmt, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	Query(query string, args ...any) (*sql.Rows, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *sql.Row
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

type Transaction

type Transaction interface {
	Tx() *sql.Tx
	IsNew() bool
	IsReadOnly() bool
	MarkAsRollbackOnly()
	IsRollbackOnly() bool
	MarkAsCompleted()
	IsCompleted() bool
}

func New

func New(tx *sql.Tx, newTransaction bool, readOnly bool) Transaction

Jump to

Keyboard shortcuts

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