Accumulates bind parameters and emits SQL fragments as iodata.
Request text reaches SQL only as a bind parameter (param/4) or through ident/1
and cast/2, which validate what they emit.
Summary
Functions
Appends already-dumped values whose placeholders are written elsewhere (spliced SQL),
keeping the numbering of later param/4 calls consistent.
Binds an integer using the shared text-to-bigint SQL representation.
CAST(<expr> AS <type>). The type name is re-validated with
PgRest.Grammar.Common.cast_name?/1; invalid input raises ArgumentError (the grammar
has already turned it into a 400, so a raise means a bug). This is the only way a
request-supplied type name reaches SQL.
A column of table_alias with its JSON path (json_path/3). As PostgREST, a path on a column
whose type (column_types, keyed by field name) is not json or jsonb reads it through
to_jsonb.
Double-quotes an identifier. Raises ArgumentError on a NUL byte.
Quoted identifiers joined with ,.
Appends JSON path steps ({:arrow | :double_arrow, key}) to column. Every key is a bind
parameter, never spliced into the SQL text.
A bound LIMIT clause, or no clause when the limit is nil.
cast/2, or expr unchanged when type is nil.
Starts an empty builder.
Binds value and returns its placeholder.
Number of parameters bound so far.
A schema-qualified, quoted relation name.
Finalises the statement: the SQL text and the parameters in placeholder order.
Types
@type mode() :: :text | :native
How a parameter value is bound.
@type t() :: %PgRest.SQL.Builder{ count: non_neg_integer(), params: [term()], repo: module() | nil }
Functions
Appends already-dumped values whose placeholders are written elsewhere (spliced SQL),
keeping the numbering of later param/4 calls consistent.
Binds an integer using the shared text-to-bigint SQL representation.
CAST(<expr> AS <type>). The type name is re-validated with
PgRest.Grammar.Common.cast_name?/1; invalid input raises ArgumentError (the grammar
has already turned it into a 400, so a raise means a bug). This is the only way a
request-supplied type name reaches SQL.
@spec column( String.t(), PgRest.AST.Field.t(), %{required(String.t()) => String.t()}, t() ) :: {iodata(), t()}
A column of table_alias with its JSON path (json_path/3). As PostgREST, a path on a column
whose type (column_types, keyed by field name) is not json or jsonb reads it through
to_jsonb.
Double-quotes an identifier. Raises ArgumentError on a NUL byte.
Quoted identifiers joined with ,.
@spec json_path(iodata(), [PgRest.AST.Field.json_step()], t()) :: {iodata(), t()}
Appends JSON path steps ({:arrow | :double_arrow, key}) to column. Every key is a bind
parameter, never spliced into the SQL text.
Array indexes are unbounded integer text: bound as text and cast, never natively.
PostgREST sends a non-negative index with a leading +, which shows in the 22003 message
of an out-of-range index, so this does too. String keys bind as a bare $n so Postgres
infers their type exactly as it does for PostgREST's untyped literals (jsonb ->> unknown
is a key lookup, text ->> unknown is 42883).
@spec limit(t(), non_neg_integer() | nil) :: {iodata(), t()}
A bound LIMIT clause, or no clause when the limit is nil.
cast/2, or expr unchanged when type is nil.
Starts an empty builder.
Options
:repo- the Ecto repo used to compile scoped Ecto queries to SQL
Binds value and returns its placeholder.
In :text mode (request-derived values) the value is bound as text and cast in SQL:
$n::text or $n::text::<type>; a list binds as $n::text[]::<type>[]. In :native
mode (values produced by Ecto.Type.dump/2) it emits $n, or $n::<type> when a type
is given. type is always trusted text (a catalog type or a fixed PgRest type), never
request text.
@spec param_count(t()) :: non_neg_integer()
Number of parameters bound so far.
A schema-qualified, quoted relation name.
Finalises the statement: the SQL text and the parameters in placeholder order.