Postgres module

query

procedure · 1 overloadsince 0.27.0Source

Runs the statement and returns its rows. Rows(Row(...)) has one field per column; when the columns are exactly one table's, it is Rows(Table) with that table's struct from db/schema.jai (row type identity, see row_type).

query :: (
    db: $D,
    $sql: string,
    args: ..Any,
    plan := Plan.AUTO,
    json := Json_Options.{},
    $call := #caller_code
) -> (Rows(#run row_type(sql, call, 1, #insert,scope(call) #run row_table_type(sql, call, 1, #insert,scope(call) #run row_table_exists(sql, call, 1)), Row(#run row_shape(sql, call, 1)))), Pg_Error)

Runs the statement and returns its rows. Rows(Row(...)) has one field per column; when the columns are exactly one table's, it is Rows(Table) with that table's struct from db/schema.jai (row type identity, see row_type).

Parameters

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.
$call := #caller_code
the code of the call, which lets the query text be checked while compiling. Leave the default.

Returns

Rows(#run row_type(sql, call, 1, #insert,scope(call) #run row_table_type(sql, call, 1, #insert,scope(call) #run row_table_exists(sql, call, 1)), Row(#run row_shape(sql, call, 1))))

See also