[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
This is a very simple tutorial on how to use the CRUD options. A more detailed tutorial is coming soon.
CREATE
One Row:
Dim Insert As Supabase_DatabaseInsert = xSupabase.Database.InsertData
Insert.From("dt_Tasks")
Dim InsertMap As Map = CreateMap("Tasks_Name":"Task 01","Tasks_Checked":False,"Tasks_CreatedAt":DateUtils.TicksToString(DateTime.Now),"Tasks_UpdatedAt":DateUtils.TicksToString(DateTime.Now))
Wait For (Insert.Insert(InsertMap).Execute) Complete (Result As SupabaseDatabaseResult)
Bulk Insert:
Dim Insert As Supabase_DatabaseInsert = xSupabase.Database.InsertData
Insert.From("dt_Tasks")
Dim lst_BulkInsert As List
lst_BulkInsert.Initialize
lst_BulkInsert.Add(CreateMap("Tasks_Name":"Task 02","Tasks_Checked":True,"Tasks_CreatedAt":DateUtils.TicksToString(DateTime.Now),"Tasks_UpdatedAt":DateUtils.TicksToString(DateTime.Now)))
lst_BulkInsert.Add(CreateMap("Tasks_Name":"Task 03","Tasks_Checked":True,"Tasks_CreatedAt":DateUtils.TicksToString(DateTime.Now),"Tasks_UpdatedAt":DateUtils.TicksToString(DateTime.Now)))
Wait For (Insert.InsertBulk(lst_BulkInsert).Execute) Complete (Result As SupabaseDatabaseResult)
B4X:
Dim Query As Supabase_DatabaseSelect = xSupabase.Database.SelectData
Query.Columns("*").From("dt_Tasks")
Query.Filter_Equal(CreateMap("Tasks_Name":"Task 02"))
Wait For (Query.Execute) Complete (DatabaseResult As SupabaseDatabaseResult)
xSupabase.Database.PrintTable(DatabaseResult)
For Each Row As Map In DatabaseResult.Rows
Log(Row.Get("Tasks_Name"))
Next
B4X:
Dim Update As Supabase_DatabaseUpdate = xSupabase.Database.UpdateData
Update.From("dt_Tasks")
Update.Update(CreateMap("Tasks_Name":"Task 02"))
Update.Eq(CreateMap("Tasks_Id":1))
Wait For (Update.Execute) Complete (Result As SupabaseDatabaseResult)
B4X:
Dim Delete As Supabase_DatabaseDelete = xSupabase.Database.DeleteData
Delete.From("dt_Tasks")
Delete.Eq(CreateMap("Tasks_Id":1))
Wait For (Delete.Execute) Complete (Result As SupabaseError)
Last edited: