Supabase.PostgREST.QueryBuilder (supabase_postgrest v1.2.2)

View Source

Handles 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

avg(column, opts \\ [])

Hleper function to apply aggregation of avg function to a specified column name. This should be used on select/3.

Parameters

  • column: The Supabase.Fetcher.Request to 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 :as value 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

count(column, opts \\ [])

Hleper function to apply aggregation of count function to a specified column name. This should be used on select/3.

Parameters

  • column: The Supabase.Fetcher.Request to 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 :as value 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

delete(b, opts \\ [])

Deletes records from a table based on the conditions specified.

Parameters

Examples

iex> PostgREST.delete(builder, returning: :representation)

See also

insert(b, data, opts \\ [])

Inserts new records into the database. Supports conflict resolution and specifying how the result should be returned.

Parameters

  • builder: The Supabase.Fetcher.Request to 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

max(column, opts \\ [])

Hleper function to apply aggregation of max function to a specified column name. This should be used on select/3.

Parameters

  • column: The Supabase.Fetcher.Request to 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 :as value 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

min(column, opts \\ [])

Hleper function to apply aggregation of min function to a specified column name. This should be used on select/3.

Parameters

  • column: The Supabase.Fetcher.Request to 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 :as value 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

select(builder, columns, opts \\ [])

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: The Supabase.Fetcher.Request instance.
  • columns: A list of column names to fetch or '*' for all columns.
  • opts: Options such as :count and :returning.

Examples

iex> PostgREST.select(builder, "*", count: :exact, returning: true)

See also

sum(column, opts \\ [])

Hleper function to apply aggregation of sum function to a specified column name. This should be used on select/3.

Parameters

  • column: The Supabase.Fetcher.Request to 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 :as value 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

update(b, data, opts \\ [])

Updates existing records in the database. Allows specifying return options and how the update is counted.

Parameters

  • builder: The Supabase.Fetcher.Request to use.
  • data: The new data for the update, typically a map or list of maps.
  • opts: Options such as :returning and :count.

Examples

iex> PostgREST.update(builder, %{name: "Doe"}, returning: :representation)

See also

upsert(b, data, opts \\ [])

Upserts data into a table, allowing for conflict resolution and specifying return options.

Parameters

  • builder: The Supabase.Fetcher.Request to 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