Supabase.Connection (supabase_connection v0.1.0)
Defines the connection to Supabase, it is an Agent that holds the connection information and the current bucket.
To start the connection you need to call Supabase.Connection.start_link/1
:
iex> Supabase.Connection.start_link(name: :my_conn, conn_info: %{base_url: "https://myapp.supabase.io", api_key: "my_api_key"})
{:ok, #PID<0.123.0>}
But usually you would add the connection to your supervision tree:
defmodule MyApp.Application do
use Application
def start(_type, _args) do
conn_info = %{base_url: "https://myapp.supabase.io", api_key: "my_api_key"}
children = [
{Supabase.Connection, conn_info: conn_info, name: :my_conn}
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
end
Once the connection is started you can use it to perform operations on the storage service, for example to list all the buckets:
iex> conn = Supabase.Connection.fetch_current_bucket!(:my_conn)
iex> Supabase.Storage.list_buckets(conn)
{:ok, [
%Supabase.Storage.Bucket{
allowed_mime_types: nil,
file_size_limit: nil,
id: "my-bucket-id",
name: "my-bucket",
public: true
}
]}
Notice that you can start multiple connections, each one with different credentials, and you can use them to perform operations on different buckets!
Fields
Currently the connection holds the following fields:
:base_url
- The base url of the Supabase API, it is usually in the formhttps://<app-name>.supabase.io
.:api_key
- The API key used to authenticate requests to the Supabase API.:access_token
- Token with specific permissions to access the Supabase API, it is usually the same as the API key.name
: Simple field to track the name of the connection, started bystart_link/1
.alias
: Field to easily manage multiple connections on aSupabase.Client
Agent.
Summary
Functions
Returns a specification to start this module under a supervisor.
Types
Link to this type
access_token()
@type access_token() :: String.t()
Link to this type
api_key()
@type api_key() :: String.t()
Link to this type
base_url()
@type base_url() :: String.t()
Link to this type
bucket()
@type bucket() :: struct()
Link to this type
params()
@type params() :: [ name: atom(), conn_info: %{ base_url: base_url(), api_key: api_key(), access_token: access_token(), bucket: bucket() } ]
Functions
Link to this function
child_spec(arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
Link to this function
fetch_current_bucket!(conn)
Link to this function
get_access_token(conn)
Link to this function
get_api_key(conn)
Link to this function
get_base_url(conn)
Link to this function
put_access_token(conn, token)
Link to this function
put_current_bucket(conn, bucket)
Link to this function
remove_current_bucket(conn)
Link to this function
retrieve_connection(name)
Link to this function