Supabase.Client (supabase_potion v0.2.2)
A client for interacting with Supabase. This module is responsible for managing the connection pool and the connection options.
Usage
Usually you don't need to use this module directly, instead you should
use the Supabase
module, available on :supabase_potion
application.
However, if you want to manage clients manually, you can leverage this module to start and stop clients dynamically. To start a single client manually, you need to add it to your supervision tree:
defmodule MyApp.Application do
use Application
def start(_type, _args) do
children = [
{Supabase.Client, name: :supabase, client_info: %Supabase.Client{}}
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
end
Notice that starting a Client in this way, Client options will not be validated, so you need to make sure that the options are correct. Otherwise application will crash.
Examples
iex> Supabase.Client.start_link(name: :supabase, client_info: client_info)
{:ok, #PID<0.123.0>}
iex> Supabase.Client.retrieve_client(:supabase)
%Supabase.Client{
name: :supabase,
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)
%Supabase.Client.Conn{
base_url: "https://<app-name>.supabase.io",
api_key: "<supabase-api-key>",
access_token: "<supabase-access-token>"
}
Summary
Functions
Returns a specification to start this module under a supervisor.
Types
params()
@type params() :: %{ name: atom(), 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(), name: atom() }
Functions
child_spec(arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
parse(attrs)
@spec parse(params()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
parse!(attrs)
retrieve_client(name)
retrieve_connection(name)
@spec retrieve_connection(name) :: Supabase.Client.Conn.t() | nil when name: atom() | pid()