Postgres module

select

procedure · 1 overloadsince 0.27.0Source

The rows of T's table that pass where, in order_by order (desc for descending), at most limit of them (-1: all) after skipping offset. from_sql replaces the table with a query of your own that returns its columns, with %name / %(expression) parameters: from_sql = "select * from users_visible_to(%viewer)". fields = "id, email" selects only those columns, and the rows are then Partial(T, "id, email").

select :: (
    db: $D,
    $T: Type,
    $where: Code = EVERY_ROW,
    $order_by: Code = NO_ORDER,
    $desc := false,
    $limit := -1,
    $offset := 0,
    $from_sql := "",
    $fields := "",
    $call := #caller_code
) -> (Rows(#insert #run orm_select_row(fields)), Pg_Error)

The rows of T's table that pass where, in order_by order (desc for descending), at most limit of them (-1: all) after skipping offset. from_sql replaces the table with a query of your own that returns its columns, with %name / %(expression) parameters: from_sql = "select * from users_visible_to(%viewer)". fields = "id, email" selects only those columns, and the rows are then Partial(T, "id, email").

Parameters

db: $D
a connection or pool.
$T: Type
the table struct.
$where: Code
the filter. Every row by default.
$order_by: Code
the sort key. No order by default.
$desc := false
sort descending.
$limit := -1
the most rows to return. -1 for all.
$offset := 0
how many rows to skip first.
$from_sql := ""
a query to select from instead of the table.
$fields := ""
the comma-separated columns to select. All by default.
$call := #caller_code
the code of the call, which lets the query text be checked while compiling. Leave the default.

Returns

Rows(#insert #run orm_select_row(fields))

See also