sqlbind

package
v0.1.8 Latest Latest
Warning

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

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

Documentation

Overview

Package sqlbind provides generated, reflection-free database/sql row mapping.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSQLExecutor = errors.New("sqlbind: no SQL executor in context")

ErrNoSQLExecutor reports that a Context does not contain a database executor. It is returned instead of panicking so generated Context wrappers remain ordinary error-returning APIs.

Functions

func Bool

func Bool(row Row, column string) (bool, error)

func Float64

func Float64(row Row, column string) (float64, error)

func ForEach

func ForEach(rows *sql.Rows, fn func(Row) error) error

ForEach scans rows without retaining the full result.

func Int

func Int(row Row, column string) (int, error)

func Int64

func Int64(row Row, column string) (int64, error)

func Key

func Key(row Row, column string) (key string, present bool, err error)

Key returns a stable grouping key. present is false for SQL NULL.

func RegisterScanRows

func RegisterScanRows[T any](fn func(*sql.Rows) ([]T, error))

RegisterScanRows registers a generated SQL tree scanner for T.

func RequiredKey

func RequiredKey(row Row, column string) (string, error)

RequiredKey is Key with NULL rejected for a root object.

func ScanRows

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

ScanRows maps joined SQL rows into a grouped object tree using generated code.

func String

func String(row Row, column string) (string, error)

func WithSQLExecutor added in v0.1.6

func WithSQLExecutor(ctx context.Context, executor SQLExecutor) context.Context

WithSQLExecutor returns a child Context containing a database executor. Framework transaction middleware can store a *sql.Tx for generated <Component>Context wrappers to resolve.

Types

type Row

type Row map[string]any

Row is a SQL row indexed by result column name.

type SQLExecutor added in v0.1.6

type SQLExecutor interface {
	ExecContext(context.Context, string, ...any) (sql.Result, error)
	QueryContext(context.Context, string, ...any) (*sql.Rows, error)
}

SQLExecutor is implemented by *sql.DB, *sql.Conn, and *sql.Tx.

func SQLExecutorFromContext added in v0.1.6

func SQLExecutorFromContext(ctx context.Context) (SQLExecutor, error)

SQLExecutorFromContext returns the executor installed by WithSQLExecutor.

Jump to

Keyboard shortcuts

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