Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var TxDefault = &sql.TxOptions{Isolation: sql.LevelDefault, ReadOnly: false}
TxDefault represents default transaction options.
var TxDefaultReadOnly = &sql.TxOptions{Isolation: sql.LevelDefault, ReadOnly: true}
TxDefaultReadOnly represents default transaction options for read-only transactions.
var TxSerializable = &sql.TxOptions{Isolation: sql.LevelSerializable, ReadOnly: false}
TxSerializable represents serializable transaction options.
var WireSet = wire.NewSet( ProvideAccessorTx, ProvideAccessor, ProvideOrmTransactor, )
WireSet provides a wire set for this package.
Functions ¶
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 ¶
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 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 ¶
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.