[B4X] Supabase - The Open Source Firebase alternative
Supabase is an open source Firebase alternative. It provides all the backend services you need to build a product. Supabase uses Postgres database with real-time capabilities. Basically, supabase provides an interface to manage postgres database that you can use to create table and insert, edit...
www.b4x.com
Listen to Postgres changes using Supabase Realtime.
Setup
[B4X] Supabase - Realtime
https://www.b4x.com/android/forum/threads/b4x-supabase-the-open-source-firebase-alternative.149855/ This is a very simple tutorial on how to use the Realtime module. A more detailed tutorial is coming soon. Step 1 Click in your project on "Project -> Build configurations -> Conditional...
www.b4x.com
Listening to ALL events
B4X:
Realtime _
.Channel("public","dt_Chat","") _
.On(Realtime.SubscribeType_PostgresChanges) _
.Event(Realtime.Event_ALL) _
.Subscribe 'subscribe to a topic - In this example we subscibe to all database changes on dt_Tasks
Wait For Realtime_Subscribed 'Successfully subscribed
Log("Subscribed to topic")
B4X:
Realtime _
.Channel("public","dt_Chat","") _
.On(Realtime.SubscribeType_PostgresChanges) _
.Event(Realtime.Event_INSERT) _
.Subscribe
B4X:
Realtime _
.Channel("public","dt_Chat","") _
.On(Realtime.SubscribeType_PostgresChanges) _
.Event(Realtime.Event_UPDATE) _
.Subscribe
B4X:
Realtime _
.Channel("public","dt_Chat","") _
.On(Realtime.SubscribeType_PostgresChanges) _
.Event(Realtime.Event_DELETE) _
.Subscribe
B4X:
Realtime _
.Channel("public","dt_Chat","") _
.On(Realtime.SubscribeType_PostgresChanges) _
.Event(Realtime.Event_INSERT) _
.On(Realtime.SubscribeType_PostgresChanges) _
.Event(Realtime.Event_UPDATE) _
.Subscribe
Filters are there to react only to certain changes. e.g. we want to have only all changes from the chat room with id 3.
In the following example we subscribe to all database changes with room_id = 3
B4X:
Realtime _
.Channel("public","dt_Chat",Realtime.BuildFilter("room_id",Realtime.Filter_Equal,"3")) _
.On(Realtime.SubscribeType_PostgresChanges) _
.Event(Realtime.Event_ALL) _
.Subscribe
B4X:
Private Sub Realtime_DataReceived(Data As SupabaseRealtime_Data)
If Data.EventType = Realtime.Event_UPDATE Then 'A record in the database was changed
For Each k As String In Data.Records.Keys
Log($"Column: "${k}" Value: "${Data.Records.Get(k)}""$)
Next
End If
End Sub