Documentation
¶
Overview ¶
Package sqlutils contains functionality to wrap existing database functionality
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithTransaction ¶
func WithTransaction(ctx context.Context, txPrep TransactionPreparer, txFunc func(*sqlx.Tx) error) error
WithTransaction is used for transactions that are execution only (i.e., no return value) and only returns an error
func WithTransactionRet ¶
func WithTransactionRet[T any](ctx context.Context, txPrep TransactionPreparer, txFunc func(*sqlx.Tx) (T, error)) (result T, txErr error)
WithTransactionRet is a wrapper function which handles creating, committing or rolling back a transaction If there are any errors when executing the txFunc, the tx is rolled back. Otherwise, the tx is committed. We use named return parameters here so that the deferred function can access and reassign the variables
Types ¶
type NamedPreparer ¶
type NamedPreparer interface { PrepareNamed(query string) (*sqlx.NamedStmt, error) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error) }
NamedPreparer is an interface used by to execute a sqlx transaction either directly or as a transacation.
type TransactionPreparer ¶
TransactionPreparer is an interface used to initiate a sqlx.TX