bind

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

README

bind — results through caller pointers

The shorter of the two result strategies. Bind(col, &dst) captures a pointer, and the select list and the scan targets come from one slice so they cannot drift apart.

Binding is an interface owned by stmt, and must stay one. The statement layer knows only that an item renders and carries an opaque target; it must never learn that the target is a pointer. That is what lets bind be its own package, and what keeps a third result strategy someone else's package rather than a fork — contrib/structbind is the proof, since a reflection-driven binder cannot use Bind at all.

Full documentation

The page for this package is docs/bind/README.md, with runnable snippets — every one of them copied from a test whose expected output go test checks. The documentation index is ../docs/README.md and the repository README is ../README.md.

Documentation

Overview

Package bind is the result strategy that writes rows through pointers the caller supplied.

It is one of two strategies and the shorter one to write: Bind(col, &dst) pairs a column with a destination, the column list and the scan targets are derived from the same slice in the same order, and nothing has to be kept in step by hand. That property is the reason the library exists in this shape.

The cost is that a bound query holds pointers into caller memory. It is therefore NOT SAFE FOR CONCURRENT USE: two goroutines executing one query interleave each other's rows into the same variables, which is a DATA RACE and reads like inert data. One and Each refuse an overlapping execution with ErrQueryInUse, but that is detection, not prevention. Build the query where its destinations live.

github.com/ubgo/sqlb/scan is the peer strategy without that hazard: it returns values rather than writing through pointers, so one Reader is safe to share across any number of concurrent executions. Neither is deprecated.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind[T any](e expr.Expr[T], dst *T) stmt.Binding

Bind pairs e with dst. The compiler rejects a dst whose type is not *T.

The pointer is captured, not the value, and it lives as long as the query does. Two consequences worth knowing before they bite: Each writes every row through the same pointer, so a callback keeping a row must copy it; and a query is not safe for concurrent use, because two goroutines would write through these pointers at once, which is a data race. Build the query where its destination lives. See One and ErrQueryInUse.

func Bindings

func Bindings(groups ...[]stmt.Binding) []stmt.Binding

Bindings concatenates binding groups in order. A composite destination uses it to join the core's bindings with each plugin's.

func Targets

func Targets(bs []stmt.Binding) []any

Targets extracts the scan pointers of bs in order, for rows.Scan.

Types

This section is empty.

Jump to

Keyboard shortcuts

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