Supabase.PostgREST.QueryBuilder (supabase_postgrest v1.2.2)
View SourceHandles operations related to building and modifying the main structure of a query.
This module includes functionality for selecting fields, inserting new records, updating existing ones, and deleting records from a specified table. These operations define the high-level intent of the query, such as whether it retrieves, modifies, or removes data.
Summary
Functions
Hleper function to apply aggregation of avg function to a specified
column name. This should be used on select/3.
Hleper function to apply aggregation of count function to a specified
column name. This should be used on select/3.
Deletes records from a table based on the conditions specified.
Inserts new records into the database. Supports conflict resolution and specifying how the result should be returned.
Hleper function to apply aggregation of max function to a specified
column name. This should be used on select/3.
Hleper function to apply aggregation of min function to a specified
column name. This should be used on select/3.
Selects records from a table. You can specify specific columns or use '*' for all columns. Options such as counting results and specifying return types can be configured.
Hleper function to apply aggregation of sum function to a specified
column name. This should be used on select/3.
Updates existing records in the database. Allows specifying return options and how the update is counted.
Upserts data into a table, allowing for conflict resolution and specifying return options.
Functions
Hleper function to apply aggregation of avg function to a specified
column name. This should be used on select/3.
Parameters
column: TheSupabase.Fetcher.Requestto use.opts.as: If specifying more than one aggregate function for the same column, you may need to rename it, so you can pass an optional:asvalue for it.
Examples
iex> alias Supabase.PostgREST, as: Q
iex> Q.select(builder, [Q.avg("amount")])
iex> alias Supabase.PostgREST, as: Q
iex> Q.select(builder, [Q.avg("amount", as: "avg_amount"), Q.sum("amount", as: "total_amount")])See also
- PostgREST official docs about aggregation functions: https://docs.postgrest.org/en/stable/references/api/aggregate_functions.html
Hleper function to apply aggregation of count function to a specified
column name. This should be used on select/3.
Parameters
column: TheSupabase.Fetcher.Requestto use.opts.as: If specifying more than one aggregate function for the same column, you may need to rename it, so you can pass an optional:asvalue for it.
Examples
iex> alias Supabase.PostgREST, as: Q
iex> Q.select(builder, [Q.avg("amount")])
iex> alias Supabase.PostgREST, as: Q
iex> Q.select(builder, [Q.avg("amount", as: "avg_amount"), Q.sum("amount", as: "total_amount")])See also
- PostgREST official docs about aggregation functions: https://docs.postgrest.org/en/stable/references/api/aggregate_functions.html
Deletes records from a table based on the conditions specified.
Parameters
builder: TheSupabase.Fetcher.Requestto use.opts: Options such as:returningand:count.
Examples
iex> PostgREST.delete(builder, returning: :representation)See also
- Supabase documentation on deletes: https://supabase.com/docs/reference/javascript/delete
Inserts new records into the database. Supports conflict resolution and specifying how the result should be returned.
Parameters
builder: TheSupabase.Fetcher.Requestto use.data: The data to be inserted, typically a map or a list of maps.opts: Options like:on_conflict,:returning, and:count.
Examples
iex> PostgREST.insert(builder, %{name: "John"}, on_conflict: "name", returning: :minimal)See also
- Supabase documentation on inserts: https://supabase.com/docs/reference/javascript/insert
Hleper function to apply aggregation of max function to a specified
column name. This should be used on select/3.
Parameters
column: TheSupabase.Fetcher.Requestto use.opts.as: If specifying more than one aggregate function for the same column, you may need to rename it, so you can pass an optional:asvalue for it.
Examples
iex> alias Supabase.PostgREST, as: Q
iex> Q.select(builder, [Q.avg("amount")])
iex> alias Supabase.PostgREST, as: Q
iex> Q.select(builder, [Q.avg("amount", as: "avg_amount"), Q.sum("amount", as: "total_amount")])See also
- PostgREST official docs about aggregation functions: https://docs.postgrest.org/en/stable/references/api/aggregate_functions.html
Hleper function to apply aggregation of min function to a specified
column name. This should be used on select/3.
Parameters
column: TheSupabase.Fetcher.Requestto use.opts.as: If specifying more than one aggregate function for the same column, you may need to rename it, so you can pass an optional:asvalue for it.
Examples
iex> alias Supabase.PostgREST, as: Q
iex> Q.select(builder, [Q.avg("amount")])
iex> alias Supabase.PostgREST, as: Q
iex> Q.select(builder, [Q.avg("amount", as: "avg_amount"), Q.sum("amount", as: "total_amount")])See also
- PostgREST official docs about aggregation functions: https://docs.postgrest.org/en/stable/references/api/aggregate_functions.html
Selects records from a table. You can specify specific columns or use '*' for all columns. Options such as counting results and specifying return types can be configured.
Note that this function does not return by default, it only build the select
expression for the query. If you want to have the selected fields returned as
response you need to pass returning: true.
Parameters
builder: TheSupabase.Fetcher.Requestinstance.columns: A list of column names to fetch or '*' for all columns.opts: Options such as:countand:returning.
Examples
iex> PostgREST.select(builder, "*", count: :exact, returning: true)See also
- Supabase select queries: https://supabase.com/docs/reference/javascript/select
Hleper function to apply aggregation of sum function to a specified
column name. This should be used on select/3.
Parameters
column: TheSupabase.Fetcher.Requestto use.opts.as: If specifying more than one aggregate function for the same column, you may need to rename it, so you can pass an optional:asvalue for it.
Examples
iex> alias Supabase.PostgREST, as: Q
iex> Q.select(builder, [Q.avg("amount")])
iex> alias Supabase.PostgREST, as: Q
iex> Q.select(builder, [Q.avg("amount", as: "avg_amount"), Q.sum("amount", as: "total_amount")])See also
- PostgREST official docs about aggregation functions: https://docs.postgrest.org/en/stable/references/api/aggregate_functions.html
Updates existing records in the database. Allows specifying return options and how the update is counted.
Parameters
builder: TheSupabase.Fetcher.Requestto use.data: The new data for the update, typically a map or list of maps.opts: Options such as:returningand:count.
Examples
iex> PostgREST.update(builder, %{name: "Doe"}, returning: :representation)See also
- Supabase documentation on updates: https://supabase.com/docs/reference/javascript/update
Upserts data into a table, allowing for conflict resolution and specifying return options.
Parameters
builder: TheSupabase.Fetcher.Requestto use.data: The data to upsert, typically a map or a list of maps.opts: Options like:on_conflict,:returning, and:count.
Examples
iex> PostgREST.upsert(builder, %{name: "Jane"}, on_conflict: "name", returning: :representation)See also
- Supabase documentation on upserts: https://supabase.com/docs/reference/javascript/upsert