dbtx

package
v0.0.0-...-94d0466 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TxDefault = &sql.TxOptions{Isolation: sql.LevelDefault, ReadOnly: false}

TxDefault represents default transaction options.

View Source
var TxDefaultReadOnly = &sql.TxOptions{Isolation: sql.LevelDefault, ReadOnly: true}

TxDefaultReadOnly represents default transaction options for read-only transactions.

View Source
var TxSerializable = &sql.TxOptions{Isolation: sql.LevelSerializable, ReadOnly: false}

TxSerializable represents serializable transaction options.

WireSet provides a wire set for this package.

Functions

func GetOrmAccessor

func GetOrmAccessor(ctx context.Context, db *gorm.DB) *gorm.DB

Types

type Accessor

type Accessor interface {
	sqlx.ExtContext // sqlx.binder + sqlx.QueryerContext + sqlx.ExecerContext
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row

	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	PreparexContext(ctx context.Context, query string) (*sqlx.Stmt, error)
	PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error)

	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}

Accessor is the SQLx database manipulation interface.

func GetAccessor

func GetAccessor(ctx context.Context, db *sqlx.DB) Accessor

GetAccessor returns Accessor interface from the context if it exists or creates a new one from the provided *sql.DB. It is intended to be used in data layer functions that might or might not be running inside a transaction.

func ProvideAccessor

func ProvideAccessor(a AccessorTx) Accessor

ProvideAccessor provides the database access interface. All DB queries can be performed.

type AccessorTx

type AccessorTx interface {
	Accessor
	Transactor
}

AccessorTx is used to access the database. It combines Accessor interface with Transactor (capability to run functions in a transaction).

func New

func New(db *sqlx.DB) AccessorTx

New returns new database Runner interface.

func ProvideAccessorTx

func ProvideAccessorTx(db *sqlx.DB) AccessorTx

ProvideAccessorTx provides the most versatile database access interface. All DB queries and transactions can be performed.

type Transaction

type Transaction interface {
	Commit() error
	Rollback() error
}

Transaction is the Go's standard sql transaction interface.

func GetTransaction

func GetTransaction(ctx context.Context) Transaction

GetTransaction returns Transaction interface from the context if it exists or return nil. It is intended to be used in transactions in service layer functions to explicitly commit or rollback transactions.

type TransactionAccessor

type TransactionAccessor interface {
	Transaction
	Accessor
}

TransactionAccessor combines data access capabilities with the transaction commit and rollback.

type Transactor

type Transactor interface {
	WithTx(ctx context.Context, txFn func(ctx context.Context) error, opts ...interface{}) error
}

func NewOrm

func NewOrm(db *gorm.DB) Transactor

func ProvideOrmTransactor

func ProvideOrmTransactor(db *gorm.DB) Transactor

func ProvideTransactor

func ProvideTransactor(a AccessorTx) Transactor

ProvideTransactor provides ability to run DB transactions.

Jump to

Keyboard shortcuts

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