db

package
v0.0.0-...-23299de Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InTx

func InTx(ctx context.Context, db *sqlx.DB, txFunc func(*TxWrap) error) (err error)

InTx executes a function in a transaction. If the function returns an error, the transaction is rolled back. If the function panics, the transaction is rolled back and the panic is re-raised. If the function returns nil, the transaction is committed.

Types

type TxWrap

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

TxWrap is a wrapper around sqlx.Tx that adds a context and redirects calls to methods like Get, Select to GetContext and SelectContext with the context it wraps.

func (*TxWrap) Exec

func (tx *TxWrap) Exec(query string, args ...any) (sql.Result, error)

func (*TxWrap) Get

func (tx *TxWrap) Get(dest interface{}, query string, args ...interface{}) error

Get is a wrapper around sqlx.Tx.GetContext that uses the context it wraps.

func (*TxWrap) Select

func (tx *TxWrap) Select(dest interface{}, query string, args ...interface{}) error

Select is a wrapper around sqlx.Tx.SelectContext that uses the context it wraps.

Jump to

Keyboard shortcuts

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