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

Community Addition: Offline Supabase #1039

Closed
tshedor opened this issue Sep 22, 2024 · 2 comments
Closed

Community Addition: Offline Supabase #1039

tshedor opened this issue Sep 22, 2024 · 2 comments

Comments

@tshedor
Copy link

tshedor commented Sep 22, 2024

Hey Supabase team, this isn't a bug report or a feature request. We've added offline functionality to the Supabase client in Brick, and I wanted to share it with the larger community.

Brick caches remote data locally so that apps always function the same offline as they do online. Models are defined in Dart while generated code handles the Supabase/SQLite querying under the hood; the application then uses a simple ORM to work with data (and even react to data). If a request is made offline, it's retried until the client comes back online.

The Brick Supabase integration adds this generation and querying capability for Supabase apps with a straightforward setup. But Supabase's client can still made offline without using Brick:

import 'package:brick_offline_first_with_rest/offline_queue.dart';
import 'package:sqflite/sqflite.dart' show databaseFactory;
import 'package:http/http.dart' as http;

final client = RestOfflineQueueClient(
  http.Client(),
  RestRequestSqliteCacheManager(
    'brick_offline_queue.sqlite',
    databaseFactory: databaseFactory,
  ),
  // Don't retry auth or storage requests; optionally add '/functions/v1' to not retry functions
  ignorePaths: {'/auth/v1','/storage/v1'},
);
final queue = RestOfflineRequestQueue(client: client);
await Supabase.initialize(..., httpClient: client); // or SupabaseClient(..., httpClient: client)
await client.requestManager.migrate();
queue.start();

If this is useful, I'd be happy to write a blog or more thorough example app to illustrate using Supabase while offline.


Sorry for opening an issue if this was the wrong place; I don't have Twitter and didn't see a link/email in the Supa Update newsletter to submit community work (although it would be a great honor if Brick's Supabase integration was mentioned in September's update). cc @devj3ns

@dshukertjr
Copy link
Member

This is awesome! Feel free to email me at [email protected] to discuss any collaboration opportunities around it!

@tshedor
Copy link
Author

tshedor commented Sep 26, 2024

@dshukertjr awesome, just sent you an email

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

2 participants