Skip to content

Commit 5e4190f

Browse files
committed
update repository readme
1 parent 3600f3e commit 5e4190f

File tree

1 file changed

+56
-0
lines changed
  • packages/brick_offline_first_with_supabase

1 file changed

+56
-0
lines changed

packages/brick_offline_first_with_supabase/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,62 @@
44

55
The `OfflineFirstWithSupabase` domain uses all the same configurations and annotations as `OfflineFirst`.
66

7+
## Repository
8+
9+
Adding offline support to Supabase is slightly more complicated than the average [../brick_offline_first_with_rest/README.md](repository process). Feedback is welcome on a smoother and more intuitive integration.
10+
11+
````dart
12+
class MyRepository extends OfflineFirstWithSupabaseRepository {
13+
static late MyRepository? _singleton;
14+
15+
MyRepository._({
16+
required super.supabaseProvider,
17+
required super.sqliteProvider,
18+
required super.migrations,
19+
required super.offlineRequestQueue,
20+
super.memoryCacheProvider,
21+
});
22+
23+
factory MyRepository() => _singleton!;
24+
25+
static void configure({
26+
required String supabaseUrl,
27+
required String apiKey,
28+
required Set<Migration> migrations,
29+
}) {
30+
// Convenience method `.clientQueue` makes creating the queue and client easy.
31+
final (client, queue) = OfflineFirstWithSupabaseRepository.clientQueue(
32+
databaseFactory: databaseFactory,
33+
);
34+
35+
final provider = SupabaseProvider(
36+
// It's important to pass the offline client to your Supabase#Client instantiation.
37+
// If you're using supabase_flutter, make sure you initialize with the clientQueue's client
38+
// before passing it here. For example:
39+
// ```dart
40+
// await Supabase.initialize(httpClient: client)
41+
// SupabaseProvider(Supabase.instance.client, modelDictionary: ...)
42+
// ```
43+
SupabaseClient(supabaseUrl, apiKey, httpClient: client),
44+
modelDictionary: supabaseModelDictionary,
45+
);
46+
47+
// Finally, initialize the repository as normal.
48+
_singleton = MyRepository._(
49+
supabaseProvider: provider,
50+
sqliteProvider: SqliteProvider(
51+
'my_repository.sqlite',
52+
databaseFactory: databaseFactory,
53+
modelDictionary: sqliteModelDictionary,
54+
),
55+
migrations: migrations,
56+
offlineRequestQueue: queue,
57+
memoryCacheProvider: MemoryCacheProvider(),
58+
);
59+
}
60+
}
61+
````
62+
763
## Models
864

965
### ConnectOfflineFirstWithSupabase

0 commit comments

Comments
 (0)