Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type QuerierContext ¶
type QuerierContext interface {
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}
QuerierContext describes a type that implements the QueryContext method, such as sql.DB and sql.Tx.
type Scannable ¶
Scannable represents a type that implements the Scan method consuming a pointer to sql.Rows. This item should declare Scan with a pointer receiver in order for it to be mutated, and in order for it to be instantiated using the data from a sql.Rows scan.
This interface allows direct access to type T as a pointer.
type Seq ¶
Seq defines a sequence iterator function for types K and T.
The Seq will accept a yield function, which will consume the types K and T yielded from the iteration, and should return a true or false on whether the yielded data is OK and the sequence should continue.
Finally, Seq returns a boolean on weather it finished successfully or not.
This involves a two-way communication between Seq and its yield function, allowing eachother to continue once the former is completed, and vice-versa.
Seq should be perceived as an idiomatic Go approach to a "for each" type of iterator.
func QueryContext ¶
func QueryContext[S Scannable[T], T any]( ctx context.Context, q QuerierContext, query string, values ...any, ) (Seq[*T, error], error)
QueryContext executes a QueryContext call using the input QuerierContext, with input context.Context, query string and values arguments. Type T must be a Scannable[T] type implementing a Scan method that consumes *sql.Rows.
This function returns a sequence iterator that yields a pointer to a type T item and an error if raised. The resulting iterator returns a boolean on weather the iteration was completed successfully or not.
This is a fail-fast implementation and the call will exit on the first raised error (either on item.Scan, or from sql.Rows.Err.