Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Supabase Extension for Loon #23

Closed
sennraf opened this issue Nov 14, 2024 · 6 comments
Closed

Feature Request: Supabase Extension for Loon #23

sennraf opened this issue Nov 14, 2024 · 6 comments

Comments

@sennraf
Copy link

sennraf commented Nov 14, 2024

Thank you for developing Loon. Looks great. Is it possible to use it with supabase?

@danReynolds
Copy link
Owner

Hey! Yea I havent used Supabase before. It looks cool. I'll need to look into writing an adapter but it should definitely be possible. Probably not too hard.

Does it currently persist data for you? Is there something about using Loon with it that would make things easier for you or you're interested in?

Have a good one

@sennraf
Copy link
Author

sennraf commented Nov 15, 2024

The reason why Loon would be interesting is because the supabase package currently does not persist data for you.

@danReynolds
Copy link
Owner

Oh cool yea I see now that they recommend SharedPreferences currently as the solution: https://pub.dev/packages/supabase_flutter#a-idcustom-localstorageacustom-localstorage

Yea looks like that could go to Loon instead. I'm going to play around with Supabase a bit.

@danReynolds
Copy link
Owner

danReynolds commented Nov 15, 2024

So i looked through the Supabase package last night. It's cool, it definitely doesn't try to persist the Postgres data. I think it would be more challenging to write than the Firestore extension for a couple reasons:

  1. It has a very private API, so you'd have to really wrap everything like all the filters in https://github.com/supabase/supabase-flutter/blob/main/packages/postgrest/lib/src/postgrest_filter_builder.dart which is somewhat tedious/error prone.

  2. It's basically just a client for interacting with your Postgres database hosted by Supabase. So essentially writing a caching layer on the client would be equivalent to somewhat implementing a sizable subset of the Postgres spec and then translating it all to how Loon represents data in collections and documents. It is do-able, but pretty involved and I'd say the bigger issue is just that it doesn't seem like the right way to be handling it. The optimal solution would be writing a proper Postgres compatible SQL-style persistence client.

That said, it does support realtime streaming and table watching:
https://pub.dev/packages/supabase_flutter
Screenshot 2024-11-15 at 9 26 35 AM
-d6c3973f4704">

If you're comfortable streaming changes to your table then what you could do is like in the image, subscribe to all changes and then dump that into a local persistent cache like Loon.

An example might look like this:

client
  .channel('public:todos')
  .onPostgresChanges(
      event: PostgresChangeEvent.all,
      schema: 'public',
      table: 'todos',
      callback: (payload) {
        print(payload);
        // {
        //   'schema': 'public',
        //   'table': 'todos',
        //   'commit_timestamp': '2021-08-01T08:00:30Z',
        //   'eventType': 'UPDATE',
        //   'new': {'id': 2, 'task': 'task 2 updated', 'status': false},
        //   'old': {'id': 2},
        //   'errors': null
        // }
        final newData = payload['new'];
        final docId = newData['id'];
        Loon.collection('todos').doc(docId).update(newData);
      });

That gets you part of the way there by at least letting you persist your data and then access it reactively through Loon across your application. Given how simple that is, I don't think it needs a full extension right now, maybe just a doc suggesting that if you want to persist to Supabase data to Loon then this approach could be an option to consider. It relies on using the streaming capabilities in Supabase though.

Let me know what you think and if you know other Flutter devs using Supabase it'd be cool to hear if they can think of a better solution.

@rayliverified
Copy link

Have you seen the discussions about Supabase building offline sync into their own packages?

https://github.com/orgs/supabase/discussions/357

@sennraf
Copy link
Author

sennraf commented Nov 15, 2024

thanks @danReynolds for the detailed write up. I will try the approach with streaming db changes into loon.

@sennraf sennraf closed this as completed Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants