Documentation
¶
Overview ¶
Package sqlbind provides generated, reflection-free database/sql row mapping.
Index ¶
- Variables
- func AppendValues[T any](b *Builder, values []T) error
- func Bool(row Row, column string) (bool, error)
- func Float64(row Row, column string) (float64, error)
- func ForEach(rows *sql.Rows, fn func(Row) error) error
- func Int(row Row, column string) (int, error)
- func Int64(row Row, column string) (int64, error)
- func Key(row Row, column string) (key string, present bool, err error)
- func RegisterScanRows[T any](fn func(*sql.Rows) ([]T, error))
- func RequiredKey(row Row, column string) (string, error)
- func ScanRows[T any](rows *sql.Rows) ([]T, error)
- func String(row Row, column string) (string, error)
- func WithSQLExecutor(ctx context.Context, executor SQLExecutor) context.Context
- type Builder
- type Execer
- type PlaceholderStyle
- type Querier
- type Row
- type SQLExecutor
- type Statement
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyValueList = errors.New("tinybind SQL: an expanded value list cannot be empty")
ErrEmptyValueList reports that an expanded value list had no elements, which would produce invalid SQL such as "IN ()".
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 AppendValues ¶ added in v0.1.16
AppendValues expands a slice into a comma-separated placeholder list. It is a package function because a Go method cannot introduce its own type parameter.
func RegisterScanRows ¶
RegisterScanRows registers a generated SQL tree scanner for T.
func RequiredKey ¶
RequiredKey is Key with NULL rejected for a root object.
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 Builder ¶ added in v0.1.16
Builder accumulates SQL text and its bound arguments. Generated statement builders write into it; template authors never construct placeholders themselves.
func NewBuilder ¶ added in v0.1.16
func NewBuilder(style PlaceholderStyle) Builder
NewBuilder returns a Builder emitting placeholders in the given style.
type Execer ¶ added in v0.1.16
Execer is the minimal executor a generated sql.exec component needs. It is satisfied by *sql.DB, *sql.Conn, and *sql.Tx.
type PlaceholderStyle ¶ added in v0.1.16
type PlaceholderStyle int
PlaceholderStyle selects the bind-placeholder syntax of the target dialect. Generated code passes the style chosen at generation time, so one Builder implementation serves every dialect.
const ( // Dollar emits PostgreSQL-style $1, $2, ... placeholders. Dollar PlaceholderStyle = iota // Question emits ?-style placeholders. Question )
type Querier ¶ added in v0.1.16
Querier is the minimal executor a generated row-returning component needs. It is satisfied by *sql.DB, *sql.Conn, and *sql.Tx.
type SQLExecutor ¶ added in v0.1.6
SQLExecutor is implemented by *sql.DB, *sql.Conn, and *sql.Tx. It combines the two minimal interfaces generated code takes, so one Context value serves both mutating and row-returning components.
func SQLExecutorFromContext ¶ added in v0.1.6
func SQLExecutorFromContext(ctx context.Context) (SQLExecutor, error)
SQLExecutorFromContext returns the executor installed by WithSQLExecutor.