sqlx

package module
v0.0.0-...-bd69f1c Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsWithinTransaction

func IsWithinTransaction(ctx context.Context) bool

func NestedTransactionsMSSQL

func NestedTransactionsMSSQL(db sqlxDB, tx *sqlx.Tx) (sqlxDB, sqlxTx)

NestedTransactionsMSSQL is a nested transactions implementation using Microsoft SQL Server savepoints.

func NestedTransactionsNone

func NestedTransactionsNone(db sqlxDB, tx *sqlx.Tx) (sqlxDB, sqlxTx)

NestedTransactionsNone is an implementation that prevents using nested transactions.

func NestedTransactionsOracle

func NestedTransactionsOracle(db sqlxDB, tx *sqlx.Tx) (sqlxDB, sqlxTx)

NestedTransactionsOracle is a nested transactions implementation using Oracle savepoints.

func NestedTransactionsSavepoints

func NestedTransactionsSavepoints(db sqlxDB, tx *sqlx.Tx) (sqlxDB, sqlxTx)

NestedTransactionsSavepoints is a nested transactions implementation using savepoints. It's compatible with PostgreSQL, MySQL, MariaDB, and SQLite.

func NewFakeTransactor

func NewFakeTransactor(db *sqlx.DB) (FakeTransactor, DBGetter)

NewFakeTransactor initializes a Transactor and DBGetter that do nothing: - the Transactor just executes its callback and returns the error, - the DBGetter just returns the DB handler. They can be used in tests where the transaction system itself doesn't need to be tested.

func NewTransactor

func NewTransactor(db *sqlx.DB, nestedTransactionStrategy nestedTransactionsStrategy) (*Transactor, DBGetter)

Types

type DB

type DB interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row

	Exec(query string, args ...any) (sql.Result, error)
	Prepare(query string) (*sql.Stmt, error)
	Query(query string, args ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *sql.Row

	GetContext(ctx context.Context, dest any, query string, args ...any) error
	MustExecContext(ctx context.Context, query string, args ...any) sql.Result
	NamedExecContext(ctx context.Context, query string, arg any) (sql.Result, error)
	PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error)
	PreparexContext(ctx context.Context, query string) (*sqlx.Stmt, error)
	QueryRowxContext(ctx context.Context, query string, args ...any) *sqlx.Row
	QueryxContext(ctx context.Context, query string, args ...any) (*sqlx.Rows, error)
	SelectContext(ctx context.Context, dest any, query string, args ...any) error

	Get(dest any, query string, args ...any) error
	MustExec(query string, args ...any) sql.Result
	NamedExec(query string, arg any) (sql.Result, error)
	NamedQuery(query string, arg any) (*sqlx.Rows, error)
	PrepareNamed(query string) (*sqlx.NamedStmt, error)
	Preparex(query string) (*sqlx.Stmt, error)
	QueryRowx(query string, args ...any) *sqlx.Row
	Queryx(query string, args ...any) (*sqlx.Rows, error)
	Select(dest any, query string, args ...any) error

	Rebind(query string) string
	BindNamed(query string, arg any) (string, []any, error)
	DriverName() string
}

DB is the common interface between *sqlx.DB and *sqlx.Tx.

type DBGetter

type DBGetter func(context.Context) DB

DBGetter is used to get the current DB handler from the context. It returns the current transaction if there is one, otherwise it will return the original DB.

type FakeTransactor

type FakeTransactor struct{}

func (FakeTransactor) WithinTransaction

func (FakeTransactor) WithinTransaction(ctx context.Context, txFunc func(context.Context) error) error

type Transactor

type Transactor struct {
	// contains filtered or unexported fields
}

func (*Transactor) WithinTransaction

func (t *Transactor) WithinTransaction(ctx context.Context, txFunc func(context.Context) error) error

Jump to

Keyboard shortcuts

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