txutil

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: GPL-2.0, GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package txutil provides shared transaction helpers for store sub-packages.

Index

Constants

This section is empty.

Variables

View Source
var LikeEscaper = strings.NewReplacer(`\`, `\\`, "%", `\%`, "_", `\_`)

LikeEscaper escapes SQL LIKE wildcards (% and _) and the escape character itself (\) in user-provided prefixes.

Functions

func AppendPrefixFilter

func AppendPrefixFilter(query string, args []any, prefix, column string) (q string, a []any)

AppendPrefixFilter adds a LIKE clause for the given column if prefix is non-empty.

func DeferRollback

func DeferRollback(tx Rollbacker)

DeferRollback is a deferred rollback helper that suppresses the expected sql.ErrTxDone error (which occurs after a successful Commit). Use as:

defer txutil.DeferRollback(tx)

Types

type Rollbacker

type Rollbacker interface {
	Rollback() error
}

Rollbacker is any type that supports Rollback (e.g. *sql.Tx or test fakes).

type TableScanner

type TableScanner[T any] struct {
	Scan     func(row interface{ Scan(...any) error }) (*T, error)
	ScanInto func(row interface{ Scan(...any) error }, dst *T) error
	Columns  string
}

TableScanner co-locates a column list with its scan function, making it impossible to use mismatched column/scan pairs in queries.

Jump to

Keyboard shortcuts

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