View Source Supabase.PostgREST.TransformBuilder (supabase_postgrest v1.0.0)
Handles transformations applied to query results.
This module provides functionality for ordering, limiting, and paginating query results. These transformations modify how data is structured or retrieved, enabling precise control over the format and amount of data returned.
Summary
Functions
Return data
as a string in CSV format.
Return data
as the EXPLAIN plan for the query.
You need to enable the db_plan_enabled setting before using this method.
Return data
as an object in GeoJSON format.
Limits the number of results returned by the query, optionally scoping this limit to a specific foreign table.
Return data
as a single object instead of an array of objects.
Query result must be one row (e.g. using .limit(1)
), otherwise this returns an error.
Order the query result by column
.
You can call this method multiple times to order by multiple columns.
You can order referenced tables, but it only affects the ordering of the parent table if you use !inner
in the query.
Limit the query result by starting at an offset from
and ending at the offset to
. Only records within this range are returned.
This respects the query order and if there is no order clause the range could behave unexpectedly.
The from
and to
values are 0-based and inclusive: range(1, 3)
will include the second, third and fourth rows of the query.
Perform a SELECT on the query result.
Rollback the query. data
will still be returned, but the query is not committed.
Return data
as a single object instead of an array of objects.
Query result must be one row (e.g. using .limit(1)
), otherwise this returns an error.
Functions
Return data
as a string in CSV format.
Examples
iex> PostgREST.csv(builder)
%Supabase.Fetcher.Request{headers: %{"accept" => "text/csv"}}
See also
Return data
as the EXPLAIN plan for the query.
You need to enable the db_plan_enabled setting before using this method.
Params
options
: options as a keyword list, these are the possibilities:analyze
: boolean, defaults tofalse
verbose
: boolean, defaults tofalse
settings
: boolean, default tofalse
buffers
: boolean, defaults tofalse
wal
: boolean, default tofalse
format
::json
or:text
, defaults to:text
Examples
iex> PostgREST.explain(builder, analyze: true, format: :json, wal: false)
%Supabase.Fetcher.Request{}
See also
Return data
as an object in GeoJSON format.
Examples
iex> PostgREST.csv(builder)
%Supabase.Fetcher.Request{headers: %{"accept" => "application/geo+json"}}
Limits the number of results returned by the query, optionally scoping this limit to a specific foreign table.
Parameters
builder
: TheSupabase.Fetcher.Request
instance.count
: The maximum number of results to return.opts
: Optional parameters, which may include a foreign table.
Examples
iex> PostgREST.limit(builder, 10)
See also
- Supabase query limits: https://supabase.com/docs/reference/javascript/using-filters#limit
Return data
as a single object instead of an array of objects.
Query result must be one row (e.g. using .limit(1)
), otherwise this returns an error.
Parameters
builder
: TheSupabase.Fetcher.Request
instance to modify.
Examples
iex> PostgREST.single(builder)
See also
- Supabase single row mode: https://supabase.com/docs/reference/javascript/using-filters#single-row
Order the query result by column
.
You can call this method multiple times to order by multiple columns.
You can order referenced tables, but it only affects the ordering of the parent table if you use !inner
in the query.
Parameters
builder
: TheSupabase.Fetcher.Request
instance.column
: The column by which to order the results.opts
: Options such as direction (:asc
or:desc
) and null handling (:null_first
or:null_last
).
Examples
iex> PostgREST.order(builder, "created_at", asc: true, null_first: false)
See also
- Supabase ordering results: https://supabase.com/docs/reference/javascript/using-filters#order
Limit the query result by starting at an offset from
and ending at the offset to
. Only records within this range are returned.
This respects the query order and if there is no order clause the range could behave unexpectedly.
The from
and to
values are 0-based and inclusive: range(1, 3)
will include the second, third and fourth rows of the query.
Parameters
builder
: TheSupabase.Fetcher.Request
instance.from
: The starting index for the results.to
: The ending index for the results, inclusive.
Examples
iex> PostgREST.range(builder, 0, 10)
See also
- Supabase range queries: https://supabase.com/docs/reference/javascript/using-filters#range
Perform a SELECT on the query result.
By default, .insert()
, .update()
, .upsert()
, and .delete()
do not
return modified rows. By calling this method, modified rows are returned in
data
.
Do not confuse with the Supabase.PostgREST.QueryBuilder.select/3
function.
Params
If called without additional arguments (besides builder), it will fallback to select all
relation (table) columns (with "*"
), otherwise you can pass a list of strings representing
the columns to be selected
Examples
iex> PostgREST.insert(builder, %{foo: :bar}) |> PostgREST.returning(~w(id foo))
See also
https://supabase.com/docs/reference/javascript/db-modifiers-select
Rollback the query. data
will still be returned, but the query is not committed.
Examples
iex> PostgREST.rollback(builder)
%Supabase.Fetcher.Request{headers: %{"prefer" => "tx=rollback"}}
Return data
as a single object instead of an array of objects.
Query result must be one row (e.g. using .limit(1)
), otherwise this returns an error.
Parameters
builder
: TheSupabase.Fetcher.Request
instance to modify.
Examples
iex> PostgREST.single(builder)
See also
- Supabase single row mode: https://supabase.com/docs/reference/javascript/using-filters#single-row