Supabase.Client (supabase_potion v0.3.7)

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

Types

@type client() :: atom() | pid()
@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

Link to this function

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this macro

is_client(v)

(macro)
@spec parse(params()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
@spec parse!(params()) :: t()
Link to this function

retrieve_auth_url(client, uri \\ "/")

Link to this function

retrieve_base_url(client)

Link to this function

retrieve_client(source)

@spec retrieve_client(name) :: {:ok, t()} | {:error, :client_not_started}
when name: atom() | pid()
Link to this function

retrieve_connection(source)

@spec retrieve_connection(name) ::
  {:ok, Supabase.Client.Conn.t()} | {:error, :client_not_started}
when name: atom() | pid()
Link to this function

retrieve_storage_url(client, uri \\ "/")

Link to this function

retrieve_url(client, uri)

Link to this function

start_link(config)

Link to this function

update_access_token(source, access_token)