B4A Library [B4X] Supabase - The Open Source Firebase alternative

Mashiane

Expert
Licensed User
Longtime User
what do you mean?
Apparently, one is able to (a) have their supabase database resising on supabase hosting and (b) can self host their own supabase database.

The link I sent above is in relation to (b) and because you have gracefully taken us through this, with time permitting, if perhaps you could also look into it. That is my request.

Thanks.

PS: Its just a matter of having more options available when one wants to deploy their back-end with self hosting / leave it at supabase cloud?
 

Waldemar Lima

Well-Known Member
Licensed User
It would be interesting to add realtime("websocket"), because it might be possible to add "data processing" within realtime("websocket") using b4j.
 

Waldemar Lima

Well-Known Member
Licensed User
Se você sabe como conectar supabase com websockets fique à vontade para me dizer, ainda não tenho ideia disso.
I know, I was doing some tricks...

When connecting using the javascript api, you can access the websocket connection data, and even the messages
 

Waldemar Lima

Well-Known Member
Licensed User
here are some explanations:

by using the js api, I can get the useful links of some modules in supabase.
including realtime...

B4X:
wss://YOURREFERENCEID.supabase.co/realtime/v1/websocket?apikey=YOURAPIKEY&vsn=1.0.0

{
    "accessToken": "YOUR PROJECT APIKEY",
    "channels": [],
    "endPoint": "wss://xxxxxxxxxxx Project Reference ID xxxxxxxxxxxxxxx.supabase.co/realtime/v1/websocket",
    "headers": {
        "X-Client-Info": "supabase-js-web/2.38.0"
    },
    "params": {
        "apikey": "xxxxxxxxxxxxx YOUR PROJECT APIKEY xxxxxxxxxxxxxxx"
    },
    "timeout": 10000,
    "heartbeatIntervalMs": 30000,
    "pendingHeartbeatRef": null,
    "ref": 0,
    "conn": null,
    "sendBuffer": [],
    "serializer": {
        "HEADER_LENGTH": 1
    },
    "stateChangeCallbacks": {
        "open": [],
        "close": [],
        "error": [],
        "message": []
    },
    "eventsPerSecondLimitMs": 100,
    "inThrottle": false,
    "reconnectTimer": {
        "tries": 0
    }
}

Messages:
 
Last edited:

Alexander Stolte

Expert
Licensed User
Longtime User
Will this be useful?
yes, but it does not work with the websocket library of b4j.
 

Alexander Stolte

Expert
Licensed User
Longtime User
I am currently working on the realtime class for Supabase. Currently only for B4A and B4I, because the websocket library in B4J with Java 11 is currently not compatible with Supabase.

I have already been able to receive RealTime messages and process them in the class. Now my challenge is to include the Auth class so that the whole thing also works with RLS enabled.
 

Waldemar Lima

Well-Known Member
Licensed User
That's excellent news...
It's a shame that it's still not possible in b4j :c

I'm available to help with whatever you need..
 

Alexander Stolte

Expert
Licensed User
Longtime User
Update
  • 1.09
    • Realtime
      • Add SupabaseRealtime
        • You can now subscribe to topics and get database changes in real time
 

Alexander Stolte

Expert
Licensed User
Longtime User
Update
  • 1.10
    • Database
      • RLS and Auth error message removed when no rows are present
      • Removed unnecessary log messages
    • Realtime
      • Works now with B4J
      • Add get isConnected - Returns true if the websocket is connected to the database
      • Removed unnecessary log messages
      • BugFixes
 

Alexander Stolte

Expert
Licensed User
Longtime User
Update
  • 1.11
    • Auth
      • Add the "Options" parameter to the SignUp function
        • sign up with additional user metadata
      • Add "Metadata" to SupabaseUser
      • BugFixes
    • Database
      • Select - Joins are now supportet
Auth - SignUp options parameter
The options parameters are used to store additional information, e.g. user name, birthday, etc. in the user record when registering new users.
B4X:
Dim AdditionalUserMetadata As Map = CreateMap("first_name":"Alexander","age":25)
Wait For (xSupabase.Auth.SignUp("test@gmail.com","Test123!",AdditionalUserMetadata)) Complete (NewUser As SupabaseUser)

This information is then stored in the "raw_user_meta_data" column in the Auth.Users table.
"Metadata" to SupabaseUser
To retrieve this info from a user, you can get the user object:
B4X:
Wait For (xSupabase.Auth.GetUser) Complete (User As SupabaseUser)
Log(User.Metadata.Get("username"))
Joins
In the following example I make a join into the "public.users" table and need the column "username" from it.
B4X:
    Dim Query As Supabase_DatabaseSelect = xSupabase.Database.SelectData
    Query.Columns("message,created_by,id, users(username)")
    Query.From("dt_Chat")
    Query.Filter_Equal(CreateMap("room_id":3))

    Wait For (Query.Execute) Complete (DatabaseResult As SupabaseDatabaseResult)
    
    For Each Row As Map In  DatabaseResult.Rows
        
        AddItem(Row.Get("message"), Row.Get("created_by") = User.Id,Row.Get("users.username"))
        
    Next
I can query the joined column with Row.Get("users.username")
 

Alexander Stolte

Expert
Licensed User
Longtime User
Update
  • 1.12
    • Realtime
      • Complete workflow redesigned to be closer to the official libraries
      • Add Filters
        • Filter_Equal, Filter_NotEqual, Filter_GreatherThan, Filter_GreatherThanOrEqual, Filter_LessThan, Filter_LessThanOrEqual, Filter_In
      • Add SubscribeType - Broadcast
        • Send ephemeral messages from client to clients with low latency.
      • Add SubscribeType - Presence
        • Track and synchronize shared state between clients.
      • Add SubscribeType - PostgresChanges
        • Listen to Postgres database changes and send them to authorized clients.
Realtime tutorial updated
B4X:
Realtime _
.Channel("public","dt_Chat",Realtime.BuildFilter("room_id",Realtime.Filter_Equal,"3")) _
.On(Realtime.SubscribeType_PostgresChanges) _
.Event(Realtime.Event_ALL) _
.Subscribe
 

Alexander Stolte

Expert
Licensed User
Longtime User
I don't understand what the filters on the channel are for
Is this to create "rooms" with specific characteristics?
have a look at the realtime tutorial
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…