querier

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FieldPointers

func FieldPointers(dest any, cols []string) ([]any, error)

FieldPointers returns scan destination pointers for dest (pointer to struct) ordered to match cols from rows.Columns().

func ScanRows

func ScanRows(rows *sql.Rows, dest any) (err error)

ScanRows scans all rows from *sql.Rows into dest (*[]*T or *[]T).

Types

type ConnectionManager

type ConnectionManager struct {
	// contains filtered or unexported fields
}

ConnectionManager wraps a *sql.DB and provides transaction management.

func NewConnectionManager

func NewConnectionManager(db *sql.DB) *ConnectionManager

NewConnectionManager returns a ConnectionManager for the given db.

func (*ConnectionManager) DB

DB returns the active transaction from ctx if one exists, otherwise returns the underlying *sql.DB. Pass the result into generated repository constructors.

func (*ConnectionManager) StartTransaction

func (cm *ConnectionManager) StartTransaction(ctx context.Context, cb func(ctx context.Context) error) error

StartTransaction begins a transaction, calls cb with a context carrying the transaction, then commits on success or rolls back on error. If cb panics, the transaction is rolled back before the panic is repropagated, so a panicking callback never leaves the transaction open. If ctx already carries a transaction, cb is called directly without starting a new one, making nested calls safe; the panic/rollback handling above only applies at the outermost call, which is the one that actually owns tx.

type Querier

type Querier interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

Querier is satisfied by both *sql.DB and *sql.Tx.

Jump to

Keyboard shortcuts

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