Supabase.Client (supabase_potion v0.5.1)
A client for interacting with Supabase. This module is responsible for managing the connection options for your Supabase project.
Usage
Generally, you can start a client by calling Supabase.init_client/3
:
iex> base_url = "https://<app-name>.supabase.io"
iex> api_key = "<supabase-api-key>"
iex> Supabase.init_client(base_url, api_key, %{})
{:ok, %Supabase.Client{}}
That way of initialisation is useful when you want to manage the connection options yourself or create one off clients.
However, starting a client directly means you have to manage the connection options yourself. To make it easier, you can use the Supabase.Client
module to manage the connection options for you.
To achieve this you can use the Supabase.Client
module in your module:
defmodule MyApp.Supabase.Client do
use Supabase.Client, otp_app: :my_app
end
This will automatically start an Agent process to manage the connection options for you. But for that to work, you need to configure your defined Supabase client in your config.exs
:
config :my_app, MyApp.Supabase.Client,
base_url: "https://<app-name>.supabase.co",
api_key: "<supabase-api-key>",
conn: %{access_token: "<supabase-access-token>"}, # optional
db: %{schema: "another"}, # default to public
auth: %{debug: true} # optional
Another alternative would be to configure your Supabase Client at runtime, while starting your application:
defmodule MyApp.Application do
use Application
def start(_type, _args) do
children = [
{MyApp.Supabase.Client, [
base_url: "https://<app-name>.supabase.co",
api_key: "<supabase-api-key>"
]}
]
opts = [strategy: :one_for_one, name: MyApp.Supabase.Client.Supervisor]
Supervisor.start_link(children, opts)
end
end
For more information on how to configure your Supabase Client with additional options, please refer to the Supabase official documentation
Examples
%Supabase.Client{
conn: %{
base_url: "https://<app-name>.supabase.io",
api_key: "<supabase-api-key>",
access_token: "<supabase-access-token>"
},
db: %Supabase.Client.Db{
schema: "public"
},
global: %Supabase.Client.Global{
headers: %{}
},
auth: %Supabase.Client.Auth{
auto_refresh_token: true,
debug: false,
detect_session_in_url: true,
flow_type: :implicit,
persist_session: true,
storage: nil,
storage_key: "sb-<host>-auth-token"
}
}
iex> Supabase.Client.retrieve_connection(%Supabase.Client{})
%Supabase.Client.Conn{
base_url: "https://<app-name>.supabase.io",
api_key: "<supabase-api-key>",
access_token: "<supabase-access-token>"
}
Summary
Functions
Given a Supabase.Client
, mounts the base url for the Auth/GoTrue feature.
Given a Supabase.Client
, return the raw the base url for the Supabase project.
Given a Supabase.Client
, return the connection informations.
Given a Supabase.Client
, mounts the base url for the Storage feature.
Types
params()
@type params() :: %{ conn: Supabase.Client.Conn.params(), db: Supabase.Client.Db.params(), global: Supabase.Client.Global.params(), auth: Supabase.Client.Auth.params() }
@type t() :: %Supabase.Client{ auth: Supabase.Client.Auth.t(), conn: Supabase.Client.Conn.t(), db: Supabase.Client.Db.t(), global: Supabase.Client.Global.t() }
Functions
parse(attrs)
@spec parse(params()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
parse!(attrs)
retrieve_auth_url(client, uri \\ "/")
Given a Supabase.Client
, mounts the base url for the Auth/GoTrue feature.
Examples
iex> Supabase.Client.retrieve_auth_url(%Supabase.Client{})
"https://<app-name>.supabase.co/auth/v1"
retrieve_base_url(client)
Given a Supabase.Client
, return the raw the base url for the Supabase project.
Examples
iex> Supabase.Client.retrieve_base_url(%Supabase.Client{})
"https://<app-name>.supabase.co"
retrieve_connection(client)
@spec retrieve_connection(t()) :: Supabase.Client.Conn.t()
Given a Supabase.Client
, return the connection informations.
Examples
iex> Supabase.Client.retrieve_connection(%Supabase.Client{})
%Supabase.Client.Conn{}
retrieve_storage_url(client, uri \\ "/")
Given a Supabase.Client
, mounts the base url for the Storage feature.
Examples
iex> Supabase.Client.retrieve_storage_url(%Supabase.Client{})
"https://<app-name>.supabase.co/storage/v1"