Postgres module

query_as

procedure · 1 overloadsince 0.27.0Source

query into your own struct. The columns are matched to fields by name, and checked: a column that can be NULL needs a Nullable field, the types must be assignable, and a Json(T) field says which type a json column holds. project_file is as for execute.

query_as :: (
    $T: Type,
    db: $D,
    $sql: string,
    args: ..Any,
    plan := Plan.AUTO,
    json := Json_Options.{},
    $project_file := "",
    $call := #caller_code
) -> (Rows(T), Pg_Error)

query into your own struct. The columns are matched to fields by name, and checked: a column that can be NULL needs a Nullable field, the types must be assignable, and a Json(T) field says which type a json column holds. project_file is as for execute.

Parameters

$T: Type
the struct each row is read into.
db: $D
a *Connection or a *Pool.
$sql: string
the statement, written at the call as a string: % marks each argument, %% is a literal %.
args: ..Any
one value per %, in order.
plan := Plan.AUTO
.AUTO runs it as a cached named statement; .CUSTOM plans it again on every run.
json := Json_Options.{}
decoding options for json columns in this query; they apply over the connection's and the column's.
$project_file := ""
the file whose project the statement belongs to; empty for the file of the call.
$call := #caller_code
the code of the call, which lets the query text be checked while compiling. Leave the default.

Returns

Rows(T)

See also