stdlib

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: MIT Imports: 7 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsWithinTransaction added in v1.1.0

func IsWithinTransaction(ctx context.Context) bool

func NestedTransactionsMSSQL

func NestedTransactionsMSSQL(db sqlDB, tx *sql.Tx) (sqlDB, sqlTx)

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

func NestedTransactionsNone

func NestedTransactionsNone(db sqlDB, tx *sql.Tx) (sqlDB, sqlTx)

NestedTransactionsNone is an implementation that prevents using nested transactions.

func NestedTransactionsOracle

func NestedTransactionsOracle(db sqlDB, tx *sql.Tx) (sqlDB, sqlTx)

NestedTransactionsOracle is a nested transactions implementation using Oracle savepoints.

func NestedTransactionsSavepoints

func NestedTransactionsSavepoints(db sqlDB, tx *sql.Tx) (sqlDB, sqlTx)

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

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
}

DB is the common interface between *sql.DB and *sql.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.

func NewFakeTransactor

func NewFakeTransactor(db *sql.DB) (transactor.Transactor, 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 *sql.DB, nestedTransactionStrategy nestedTransactionsStrategy) (transactor.Transactor, DBGetter)

Jump to

Keyboard shortcuts

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