Supabase.PostgREST (supabase_postgrest v1.0.1)
View SourceProvides a suite of functions to interact with a Supabase PostgREST API, allowing for construction and execution of queries using a fluent interface. This module is designed to facilitate the building of complex queries and their execution in the context of a Supabase database application.
For detailed usage examples and more information, refer to the official Supabase documentation: https://supabase.com/docs
Summary
Functions
Executes the query built using the Builder instance and returns the result.
Executes the query and maps the resulting data to a specified schema struct, useful for casting the results to Elixir structs.
Builds a query using the Finch HTTP client, formatting the request appropriately. Returns the HTTP request without executing it.
Initializes a Builder
for a specified table and client.
Perform a function call.
Select a schema to query or perform an function (rpc) call. The schema needs to be on the list of exposed schemas inside Supabase.
Overrides the default media type accept
header, which can control
the represation of the PostgREST response
Functions
Executes the query built using the Builder instance and returns the result.
Parameters
builder
: The Builder or Builder instance to execute.
Examples
iex> PostgREST.execute(builder)
See also
- Supabase query execution: https://supabase.com/docs/reference/javascript/performing-queries
Executes the query and maps the resulting data to a specified schema struct, useful for casting the results to Elixir structs.
Parameters
builder
: The Builder or Builder instance to execute.schema
: The Elixir module representing the schema to which the results should be cast.
Examples
iex> PostgREST.execute_to(builder, User)
See also
- Supabase query execution and schema casting: https://supabase.com/docs/reference/javascript/performing-queries
Builds a query using the Finch HTTP client, formatting the request appropriately. Returns the HTTP request without executing it.
Parameters
builder
: The Builder or Builder instance to execute.
Examples
iex> PostgREST.execute_to_finch_request(builder)
See also
- Supabase query execution: https://supabase.com/docs/reference/javascript/performing-queries
Initializes a Builder
for a specified table and client.
Parameters
client
: The Supabase client used for authentication and configuration.table
: The database relation name as a string.
Examples
iex> PostgREST.from(client, "users")
%Builder{}
See also
- Supabase documentation on initializing queries: https://supabase.com/docs/reference/javascript/from
Perform a function call.
This function returns a Supabase.Fetcher.Request
builder that can be safely
pipelined to Supabase.PostgREST.FilterBuilder
functions.
Params
client
: TheSupabase.Client
to perform the function call.fn
: The function name to call.args
: The arguments to pass to the function call as a map.options
: Named parameters:options.head
: When set totrue
,data
will not be returned. Useful if you only need the count.options.get
: When set totrue
, the function will be called with read-only access mode.options.count
: Count algorithm to use to count rows returned by the function. Only applicable for set-returning functions."exact"
: Exact but slow count algorithm. Performs aCOUNT(*)
under the hood."planned"
: Approximated but fast count algorithm. Uses the Postgres statistics under the hood."estimated"
: Uses exact count for low numbers and planned count for high numbers.
Select a schema to query or perform an function (rpc) call. The schema needs to be on the list of exposed schemas inside Supabase.
Parameters
schema
: the schema to operate on, default to theSupabase.Client
DB config
Examples
iex> builder = Supabase.PostgREST.from(client, "users")
iex> Supabase.PostgREST.schema(builder, private)
Overrides the default media type accept
header, which can control
the represation of the PostgREST response
Examples
iex> q = PostgREST.from(client, "users")
iex> q = PostgREST.with_custom_media_type(q, :csv)
iex> PostgREST.execute(q)
{:ok, "id,name
1,john 2,maria"}