View Source Supabase.PostgREST.QueryBuilder (supabase_postgrest v0.2.0)

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

Deletes records from a table based on the conditions specified in the Builder.

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

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.

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

delete(b, opts \\ [])

Deletes records from a table based on the conditions specified in the Builder.

Parameters

  • builder: The Builder to use.
  • opts: Options such as :returning and :count.

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 Builder 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

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 Builder 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

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

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

Parameters

  • builder: The Builder 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 Builder 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