Documentation
¶
Overview ¶
Package sqlbind provides generated, reflection-free database/sql row mapping.
Index ¶
- Variables
- 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 Row
- type SQLExecutor
Constants ¶
This section is empty.
Variables ¶
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 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 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.