sqlx

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFoundError           = errors.New("not found")
	ErrUnexpectedRowCountError = errors.New("unexpected row count")
)

Functions

func IScanRows

func IScanRows[T any](rows *sqlx.Rows, processFunc func(T) error) error

IScanRows scans each row into the indicated struct, and calls the process function on it, stopping on the first error. It delegates the closing of the rows object to the caller

func RequireExactSelectNamedCtx

func RequireExactSelectNamedCtx[T any](ctx context.Context, expected int, db sqlx.ExtContext, query string, args any) ([]T, error)

RequireExactSelectNamedCtx is like SelectNamedCtx, except it enforces that the number of rows returned matches an expected value

func ScanRows

func ScanRows[T any](rows *sqlx.Rows) ([]T, error)

ScanRows scans each row object into the indicated struct, returning a list of all objects. It delegates the closing of the rows object to the caller

func SelectNamedCtx

func SelectNamedCtx[T any](ctx context.Context, db sqlx.ExtContext, query string, args any) ([]T, error)

SelectNamedCtx executes a query with named paramters, and scans the results into the supplied struct

func WithTransaction

func WithTransaction(db *sqlx.DB, workFunc func(*sqlx.Tx) error) error

WithTransaction is like WithTransactionReturning except does not return a value

func WithTransactionReturning

func WithTransactionReturning[T any](db *sqlx.DB, workFunc func(tx *sqlx.Tx) (T, error)) (T, error)

WithTransactionReturning executes the provided function against the provided DB, rolling back if the given function returns error, or committing otherwise. The return value from the work function will be returned on success

Types

This section is empty.

Jump to

Keyboard shortcuts

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