You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Complete SDK and APIs integrations with Supabase
4
4
5
-
This is a monorepo with all integrations.
5
+
This monorepo houses the collection of Elixir SDK packages for integrating with Supabase, the open-source Firebase alternative. Our goal is to offer developers a seamless integration experience with Supabase services using Elixir.
6
6
7
-
## Installation
7
+
## Packages Overview
8
+
9
+
-**Supabase**: Main entrypoint for the Supabase SDK library, providing easy management for Supabase clients and connections.
10
+
-**Supabase Connection**: Handles individual connections to Supabase, encapsulating the API endpoint and credentials.
11
+
-**Supabase Storage**: Offers developers a way to store large objects like images, videos, and other files.
12
+
-**Supabase PostgREST**: Directly turns your PostgreSQL database into a RESTful API using PostgREST.
13
+
-**Supabase Realtime**: Provides a realtime websocket API, enabling listening to database changes.
14
+
-**Supabase Auth**: A comprehensive user authentication system, complete with email sign-in, password recovery, session management, and more.
15
+
-**Supabase UI**: UI components to help build Supabase-powered applications quickly.
16
+
-**Supabase Fetcher**: Customized HTTP client for making requests to Supabase APIs.
17
+
18
+
## Getting Started
19
+
20
+
### Installation
21
+
22
+
To install the complete SDK:
8
23
9
24
```elixir
10
25
defdepsdo
11
26
[
12
-
{:supabase_potion, "~> 0.1.0"}
27
+
{:supabase_potion, "~> 0.1"}
13
28
]
14
29
end
15
30
```
16
31
17
-
Notice that this would install ALL existing Supabase integrations of this project.
18
-
If you only one or two, prefer to install specific integrations, like:
32
+
Or, install specific packages as needed:
19
33
20
34
```elixir
21
35
defdepsdo
22
36
[
23
-
{:supabase_storage, "~> 0.1.0"},
24
-
{:supabase_auth, "~> 0.1.0"},
37
+
{:supabase_storage, "~> 0.1"},
38
+
{:supabase_realtime, "~> 0.1"},
39
+
# ... add other packages
25
40
]
26
41
end
27
42
```
28
43
44
+
### Clients vs Connections
45
+
46
+
A `Supabase.Client` is an Agent that holds general information about Supabase, that can be used to intereact with any of the children integrations, for example: `Supabase.Storage` or `Supabase.UI`.
47
+
48
+
Also a `Supabase.Client` holds a list of `Supabase.Connection` that can be used to perform operations on different buckets, for example.
49
+
50
+
`Supabase.Client` is defined as:
51
+
52
+
-`:name` - the name of the client, started by `start_link/1`
53
+
-`:connections` - a list of `%{conn_alias => conn_name}`, where `conn_alias` is the alias of the connection and `conn_name` is the name of the connection.
54
+
-`:db` - default database options
55
+
-`:schema` - default schema to use, defaults to `"public"`
56
+
-`:global` - global options config
57
+
-`:headers` - additional headers to use on each request
58
+
-`:auth` - authentication options
59
+
-`:auto_refresh_token` - automatically refresh the token when it expires, defaults to `true`
60
+
-`:debug` - enable debug mode, defaults to `false`
61
+
-`:detect_session_in_url` - detect session in URL, defaults to `true`
62
+
-`:flow_type` - authentication flow type, defaults to `"web"`
63
+
-`:persist_session` - persist session, defaults to `true`
64
+
-`:storage` - storage type
65
+
-`:storage_key` - storage key
66
+
67
+
68
+
On the other side, a `Supabase.Connection` is an Agent that holds the connection information and the current bucket, being defined as:
69
+
70
+
-`:base_url` - The base url of the Supabase API, it is usually in the form `https://<app-name>.supabase.io`.
71
+
-`:api_key` - The API key used to authenticate requests to the Supabase API.
72
+
-`:access_token` - Token with specific permissions to access the Supabase API, it is usually the same as the API key.
73
+
-`:name` - Simple field to track the name of the connection, started by `start_link/1`.
74
+
-`:alias` - Field to easily manage multiple connections on a `Supabase.Client` Agent.
75
+
-`:bucket` - The current bucket to perform operations on.
76
+
77
+
In simple words, a `Supabase.Client` is a container for multiple `Supabase.Connection`, and each `Supabase.Connection` is a container for a single bucket.
This will automatically adds the Connection instance to a `DynamicSupervisor` that can be found in the [`Supabase.Connection`](./apps/supabase_connection/lib/supabase/connection_supervisor.ex) specific module documentation.
88
+
89
+
For manually Connection creation and management, please refer to the corresponding documentation:
This will automatically adds the Client instance to a `DynamicSupervisor` that can be found in the [`Supabase.ClientSupervisor`](./apps/supabase/lib/supabase/client_supervisor.ex) specific module documentation.
102
+
103
+
For manually Client creation and management, please refer to the corresponding documentation:
The Supabase Elixir SDK is a powerful library that enables seamless integration with [Supabase](https://supabase.io/), a cloud-based platform that provides a suite of tools and services for building modern web and mobile applications. This SDK allows you to interact with various Supabase services, such as storage, authentication, and realtime functionality, directly from your Elixir application.
6
+
7
+
## Installation
8
+
9
+
To get started with the Supabase Elixir SDK, you need to add it to your Elixir project's dependencies. Open your `mix.exs` file and add the following line to the `deps` function:
10
+
11
+
```elixir
12
+
defdepsdo
13
+
[
14
+
{:supabase_potion, "~> 0.1"}
15
+
]
16
+
end
17
+
```
18
+
19
+
After adding the dependency, run `mix deps.get` to fetch and install the SDK.
20
+
21
+
## Usage
22
+
23
+
The Supabase Elixir SDK provides a flexible way to manage `Supabase.Client` instances, which can, in turn, manage multiple `Supabase.Connection` instances. Here's a brief overview of the key concepts:
24
+
25
+
-**Supabase.Client**: This represents a container for multiple connections and holds general information about your Supabase setup. It can be used to interact with various Supabase services.
26
+
27
+
-**Supabase.Connection**: A connection holds information about the connection to the Supabase API, including the base URL, API key, and access token. Each connection can be associated with a specific bucket for performing operations.
28
+
29
+
### Starting a Connection
30
+
31
+
To start a new connection, you can use the `Supabase.Connection.start_link/1` function. For example:
After starting one or more connections, you can start a client using the `Supabase.Client.start_link/1` function. However, it's recommended to use `Supabase.init_client/2`, which allows you to pass client options and a list of connections that the client will manage. For example:
You can choose to install only specific packages if you don't need the complete functionality. Just add the desired packages to your `deps` list in the `mix.exs` file.
66
+
67
+
For more detailed documentation, refer to the [supabase_connection documentation](https://hexdocs.pm/supabase_connection).
68
+
69
+
## Supabase Services
70
+
71
+
The Supabase Elixir SDK allows you to interact with various Supabase services:
72
+
73
+
### Supabase Storage
74
+
75
+
Supabase Storage is a service for storing large objects like images, videos, and other files. It provides a simple API with strong consistency, similar to AWS S3.
76
+
77
+
### Supabase PostgREST
78
+
79
+
PostgREST is a web server that turns your PostgreSQL database into a RESTful API. It automatically generates API endpoints and operations based on your database's structure and permissions.
80
+
81
+
### Supabase Realtime
82
+
83
+
Supabase Realtime offers a realtime WebSocket API powered by PostgreSQL notifications. You can use it to listen to changes in your database and receive updates instantly as they happen.
84
+
85
+
### Supabase Auth
86
+
87
+
Supabase Auth is a comprehensive user authentication system that includes features like email and password sign-in, email verification, password recovery, session management, and more, out of the box.
88
+
89
+
### Supabase UI
90
+
91
+
Supabase UI provides a set of UI components to help you build Supabase-powered applications quickly. It's built on top of Tailwind CSS and Headless UI, and it's fully customizable. The package even includes `Phoenix.LiveView` components!
92
+
93
+
### Supabase Fetcher
94
+
95
+
Supabase Fetcher is a customized HTTP client for Supabase, mainly used in Supabase Potion. It gives you complete control over how you make requests to any Supabase API.
96
+
97
+
---
98
+
99
+
With the Supabase Elixir SDK, you have the tools you need to supercharge your Elixir applications by seamlessly integrating them with Supabase's powerful cloud services. Happy coding! 😄
0 commit comments