sqlutils

package
v0.0.0-...-8ca2828 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package sqlutils contains functionality to wrap existing database functionality

Index

Constants

This section is empty.

Variables

View Source
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 ProcessDataBaseErrors(message string, err error) error

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

type TransactionPreparer interface {
	Beginx() (*sqlx.Tx, error)
}

TransactionPreparer is an interface used to initiate a sqlx.TX

Jump to

Keyboard shortcuts

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