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 ¶
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.
Types ¶
This section is empty.