Skip to content

Commit c557b69

Browse files
FalkWolskygitbook-bot
authored andcommitted
GITBOOK-180: Supabase integration to Lowcoder
1 parent d35ceb3 commit c557b69

File tree

8 files changed

+166
-0
lines changed

8 files changed

+166
-0
lines changed
359 KB
Loading

docs/SUMMARY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
* [SQL Databases](connect-your-data/data-sources-in-lowcoder/sql-databases/README.md)
7878
* [MySQL](connect-your-data/data-sources-in-lowcoder/sql-databases/mysql.md)
7979
* [MariaDB](connect-your-data/data-sources-in-lowcoder/sql-databases/mariadb.md)
80+
* [Supabase](connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/README.md)
81+
* [Supabase PostgreSQL](connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/supabase-postgresql.md)
82+
* [Supabase Assets API](connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/supabase-assets-api.md)
83+
* [Supabase Management API](connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/supabase-management-api.md)
84+
* [Supabase RealTime](connect-your-data/data-sources-in-lowcoder/sql-databases/supabase/supabase-realtime.md)
8085
* [PostgreSQL](connect-your-data/data-sources-in-lowcoder/sql-databases/postgresql.md)
8186
* [Microsoft SQL Server](connect-your-data/data-sources-in-lowcoder/sql-databases/microsoft-sql-server.md)
8287
* [Oracle](connect-your-data/data-sources-in-lowcoder/sql-databases/oracle.md)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Supabase
2+
3+
Supabase is an open-source backend-as-a-service (BaaS) platform that provides developers with a set of tools to build, manage, and scale applications. It aims to simplify the process of setting up a backend by offering various services out of the box, similar to Firebase, but with an emphasis on open standards and flexibility.
4+
5+
### Key Features :
6+
7+
1. **PostgreSQL Database**: Provides a managed PostgreSQL database with SQL querying, relational data, and full-text search capabilities.
8+
2. **Realtime Subscriptions**: Enables live updates by sending data changes (insert, update, delete) to connected clients in real time.
9+
3. **Authentication**: Built-in authentication system supporting email/password, OAuth providers (Google, GitHub), and custom auth systems.
10+
4. **Storage**: Offers scalable storage for managing media files like images and videos, ideal for handling user uploads.
11+
5. **RESTful API**: Automatically generates RESTful APIs based on your database schema for easy interaction with the backend.
12+
6. **Edge Functions**: Serverless functions that allow you to write custom backend logic without managing servers.
13+
7. **Open-Source**: Fully open-source, enabling hosting on your own infrastructure and avoiding vendor lock-in.
14+
8. **Frontend Integration**: Supports modern frontend frameworks like React, Vue, and Next.js, with SDKs for seamless backend interaction.
15+
16+
### Use Cases for Supabase :
17+
18+
* Building applications with real-time features like chat apps or live collaboration tools.
19+
* Projects that require user authentication and role-based access control.
20+
* Storing and managing media files like images, videos, or documents.
21+
* Rapidly building and scaling applications without setting up custom backend infrastructure.
22+
23+
Let's explore some of the core features of Supabase, one by one.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Supabase Assets API
2+
3+
The **Supabase Storage** (or Assets/Storage) feature provides a scalable, secure, and easy-to-use solution for managing and serving files such as images, videos, documents, and other types of media. This feature is built to handle file storage needs for modern web and mobile applications, offering direct integration with your backend database and user authentication systems.
4+
5+
### Prerequisites : 
6+
7+
* Get the Supabase Project parameteres from API settings from your Supabase Project.
8+
9+
### Connecting to Supabase Assets API : 
10+
11+
Follow the steps below : 
12+
13+
1. Create a new data source in two ways. Note that this permission is restricted to workspace admins and developers.
14+
1. Navigate to the **Data Sources** tab on [Lowcoder Homepage](http://app.lowcoder.cloud/) and click **New data source**.
15+
2. When creating a new query in the app editor, click **+ New** > **+ New data source**.
16+
2. Navigate to **Assets & Storage** section and click on **Supabase Assets** option.
17+
3. Set its name and configure general settings, including your Supabase Project URL and API key.
18+
4. Click **Save**, and it will be saved to your data source library.
19+
20+
### Demo : 
21+
22+
Let's show you how we can use the Supabase Storage feature to Upload and Retrieve data to/from Supabase. 
23+
24+
{% embed url="https://demos.lowcoder.cloud/demo/cm0p82k14000110hfpa1xr8da" %}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Supabase Management API
2+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Supabase PostgreSQL
2+
3+
Every Supabase project is a dedicated PostgreSQL database, trusted by millions of developers. PostgreSQL is a powerful open-source relational database management system (RDBMS), renowned for stability, scalability, and robustness. It is an ideal choice for applications that require data consistency and reliability.
4+
5+
### Prerequisites <a href="#prerequisites" id="prerequisites"></a>
6+
7+
* Get PostgreSQL database connection parameters from the database owner.
8+
* Refer to IP allowlist to add IP addresses of Lowcoder to your allowlist (if needed).
9+
10+
### Connect to PostgreSQL data source <a href="#connect-to-postgresql-data-source" id="connect-to-postgresql-data-source"></a>
11+
12+
Follow the steps below:
13+
14+
1. Create a new data source in two ways. Note that this permission is restricted to workspace admins and developers.
15+
* Navigate to the **Data Sources** tab on [Lowcoder Homepage](http://app.lowcoder.cloud/) and click **New data source**.
16+
* When creating a new query in the app editor, click **+ New** > **+ New data source**.
17+
2. Select **Database** > **PostgreSQL** as the data source type.
18+
3. Set its name and configure general settings, including host, port, and database name. You can also set the user name and a password.
19+
4. (Optional) Click **Test connection** to check whether the new data source is successfully connected.
20+
5. Click **Save**, and it will be saved to your data source library.
21+
22+
### Demo :&#x20;
23+
24+
{% embed url="https://demos.lowcoder.cloud/demo/clzmno7d50b0prfaixv9i8nxc" %}
25+
26+
\
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Supabase RealTime
2+
3+
Supabase's **Realtime** feature is a powerful service that allows developers to build interactive, real-time applications by enabling instant updates to frontend clients when the underlying database changes. It is built on top of PostgreSQL's `logical replication` feature and uses WebSockets to push changes to subscribed clients. Here's a detailed explanation of how it works and its key features:
4+
5+
### How Supabase RealTime Works
6+
7+
* **PostgreSQL Logical Replication**: Supabase RealTime leverages PostgreSQL’s logical replication feature to stream database changes (inserts, updates, deletes) in real-time. Logical replication is a native PostgreSQL feature that captures changes from specific tables or schemas.
8+
* **WebSocket Connection**: Once changes are detected via logical replication, they are broadcasted to all connected clients using WebSockets. Clients can subscribe to database tables or specific channels, and any changes are immediately pushed to them.
9+
10+
### Key Features of Supabase RealTime
11+
12+
* **Table Subscriptions**: You can subscribe to changes in specific database tables. For example, if you have a `users` table and want to know when a new user is created or updated, you can subscribe to this table, and Supabase will notify the client in real-time.
13+
* **Event Types**: Supabase RealTime supports three types of events that clients can subscribe to:
14+
* **INSERT**: Triggered when a new row is added to the table.
15+
* **UPDATE**: Triggered when an existing row is modified.
16+
* **DELETE**: Triggered when a row is deleted from the table.
17+
* **Row-Level Security**: Supabase RealTime respects PostgreSQL’s row-level security (RLS) policies. This ensures that clients can only receive updates for rows they have permission to access. You can enforce fine-grained security policies on a per-table or per-row basis.
18+
* **Custom Channels**: In addition to subscribing to database changes, Supabase RealTime allows you to create and subscribe to custom channels for broadcasting arbitrary events, which can be useful for other real-time features in your app, such as chat or live notifications.
19+
* **Filter Queries**: You can filter the real-time data updates to receive notifications only for specific changes that match certain conditions. This helps in optimizing the flow of real-time updates for clients that are interested in specific data.
20+
21+
More details related to Supabase RealTime can be be found here on their official website :[https://supabase.com/docs/guides/realtime](https://supabase.com/docs/guides/realtime)&#x20;
22+
23+
### Setting Up Supabase RealTime :&#x20;
24+
25+
#### 1. Enable RealTime
26+
27+
First, make sure Realtime is enabled in your Supabase project. This is usually done in the Supabase dashboard by toggling on the Realtime feature for specific tables or schemas.
28+
29+
<figure><img src="../../../../.gitbook/assets/frame_generic_light.png" alt=""><figcaption><p>Enabling RealTime on a Supabase Table</p></figcaption></figure>
30+
31+
#### 2. Client Side Subscription / Initiating Connection
32+
33+
Once RealTime is enabled, initiate the connection to Supabase through a Stream query. Following is the formate for Stream query that you can use to make the connection to Supabase.
34+
35+
```
36+
wss://{{your_supabase_project_reference_id}}.supabase.co/realtime/v1/websocket?apikey={{your_supabase_project_api_key}}&log_level=info&vsn=1.0.0
37+
```
38+
39+
Supabase Project reference ID can be found in **Settings > Project Settings > General Settings.**
40+
41+
API key can be found in **Settings > Configuration > API > Project API keys.** Use the Anon Public key.
42+
43+
#### 3. Requesting Features/Services to use
44+
45+
After a successful connection, you need to subscribe to the changes on a Schema/Table that you want to listen to. PostgreSQL changes ( Insert, Update, Delete ) on an individual/multiple Tables in a Schema or all the tables in a Schema.&#x20;
46+
47+
```
48+
{
49+
"event": "phx_reply",
50+
"topic": string,
51+
"payload": {
52+
"response": {
53+
"postgres_changes": [
54+
{
55+
"id": number,
56+
"event": "*" | "INSERT" | "UPDATE" | "DELETE",
57+
"schema": string,
58+
"table": string,
59+
"filter": string + '=' + "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "in" + '.' + string
60+
}
61+
]
62+
},
63+
"status": "ok" | "error"
64+
},
65+
"ref": string
66+
}
67+
```
68+
69+
#### 4. Keeping the Connection alive
70+
71+
The connection get timeout automatically after some time. So, to keep the connection alive we need to send the heartbeat after every 30 seconds. Use following code to send the Heartbeat request :&#x20;
72+
73+
```
74+
{
75+
"event": "heartbeat",
76+
"topic": "phoenix",
77+
"payload": {},
78+
"ref": string
79+
}
80+
```
81+
82+
### Demo&#x20;
83+
84+
Now, let's show you a working demo where in a Ecommerce App, Admins will get RealTime notifications from Supabase whenever a Customer creates a new Order .
85+
86+
{% embed url="https://demos.lowcoder.cloud/demo/cm0tnfr4t0mc1k62w6s22yolv" %}

0 commit comments

Comments
 (0)