Supabase.Client (supabase v0.1.0)

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: %{connections: %{default: :supabase}}}
    ]

    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,
  connections: %{
    default: :supabase
  },
  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: nil,
    persist_session: true,
    storage: nil,
    storage_key: nil
  }
}

iex> Supabase.Client.retrieve_connections(:supabase)
%{
  default: :supabase
}

Summary

Functions

Returns a specification to start this module under a supervisor.

Types

@type auth() :: %Supabase.Client.Auth{
  auto_refresh_token: boolean(),
  debug: boolean(),
  detect_session_in_url: boolean(),
  flow_type: String.t(),
  persist_session: boolean(),
  storage: String.t(),
  storage_key: String.t()
}
@type db() :: %Supabase.Client.Db{schema: String.t()}
@type global() :: %Supabase.Client.Global{headers: Map.t()}
@type params() :: [
  name: atom(),
  client_info: %{
    connections: %{required(atom()) => atom()},
    db: %{schema: String.t()},
    global: %{headers: Map.t()},
    auth: %{
      auto_refresh_token: boolean(),
      debug: boolean(),
      detect_session_in_url: boolean(),
      flow_type: String.t(),
      persist_session: boolean(),
      storage: String.t(),
      storage_key: String.t()
    }
  }
]
@type t() :: %Supabase.Client{
  auth: auth(),
  connections: %{required(atom()) => atom()},
  db: db(),
  global: global(),
  name: atom()
}

Functions

Link to this function

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec parse!(map()) :: t()
Link to this function

retrieve_client(pid)

@spec retrieve_client(pid()) :: t()
Link to this function

retrieve_connections(pid)

@spec retrieve_connections(pid()) :: %{required(atom()) => atom()}
Link to this function

start_link(config)