SupabasePotion.Client (supabase_potion v0.6.1)

Summary

Functions

Returns a specification to start this module under a supervisor.

Retrieve the client instance from the Agent process, so you can use it to interact with the Supabase API.

This function is an alias for start_link/1 with no arguments.

This function updates the access_token field of client that will then be used by the integrations as the Authorization header in requests, by default the access_token have the same value as the api_key.

Start an Agent process to manage the Supabase client instance.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_client(pid \\ __MODULE__)

Retrieve the client instance from the Agent process, so you can use it to interact with the Supabase API.

init()

This function is an alias for start_link/1 with no arguments.

set_auth(pid \\ __MODULE__, token)

This function updates the access_token field of client that will then be used by the integrations as the Authorization header in requests, by default the access_token have the same value as the api_key.

start_link(opts \\ [])

Start an Agent process to manage the Supabase client instance.

Usage

First, define your client module and use the Supabase.Client module:

defmodule MyApp.Supabase.Client do
  use Supabase.Client, otp_app: :my_app
end

Note that you need to configure it with your Supabase project details. You can do this by setting the base_url and api_key in your config.exs file:

config :supabase_potion, SupabasePotion.Client,
  base_url: "https://<app-name>.supabase.co",
  api_key: "<supabase-api-key>",
  # additional options
  access_token: "<supabase-access-token>",
  db: [schema: "another"],
  auth: [debug: true]

Then, on your application.ex file, you can start the agent process by adding your defined client into the Supervision tree of your project:

def start(_type, _args) do
  children = [
    SupabasePotion.Client
  ]

  Supervisor.init(children, strategy: :one_for_one)
end

For alternatives on how to start and define your Supabase client instance, please refer to the Supabase.Client module documentation.

For more information on how to start an Agent process, please refer to the Agent module documentation.