Documentation
¶
Overview ¶
Package sqlutils contains functionality to wrap existing database functionality
Index ¶
- Variables
- func ProcessDataBaseErrors(message string, err error) error
- func WithTransaction(ctx context.Context, txPrep TransactionPreparer, txFunc func(*sqlx.Tx) error) error
- func WithTransactionRet[T any](ctx context.Context, txPrep TransactionPreparer, ...) (result T, txErr error)
- type NamedPreparer
- type TransactionPreparer
Constants ¶
This section is empty.
Variables ¶
var ErrDuplicateConstraint *errDupConstraint
ErrDuplicateConstraint is a pointer to the errDupConstraint error, which can be used to verify if an error is of this specific type.
Functions ¶
func ProcessDataBaseErrors ¶
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