OfflineFirstWithSupabaseRepository<TRepositoryModel extends OfflineFirstWithSupabaseModel> class abstract

Ensures the remoteProvider is a SupabaseProvider.

Care should be given to attach an offline queue to the provider using the static convenience method clientQueue.

import 'package:sqflite/sqflite.dart' show databaseFactory;
import 'package:my_package/brick/brick.g.dart';

final (client, queue) = OfflineFirstWithSupabaseRepository.clientQueue(
  databaseFactory: databaseFactory
);
final provider = SupabaseProvider(
  SupabaseClient(supabaseUrl, supabaseAnonKey, httpClient: client),
  modelDictionary: supabaseModelDictionary,
);

class MyRepository extends OfflineFirstWithSupabaseRepository {
  MyRepository() : super(
    supabaseProvider: provider,
    sqliteProvider: SqliteProvider(databaseFactory),
    memoryCacheProvider: MemoryCacheProvider(),
    migrations: migrations,
    offlineRequestQueue: queue,
  );
}

Constructors

OfflineFirstWithSupabaseRepository.new({bool? autoHydrate, String? loggerName, MemoryCacheProvider<SqliteModel>? memoryCacheProvider, required Set<Migration> migrations, required SupabaseProvider supabaseProvider, required SqliteProvider<SqliteModel> sqliteProvider, required RestOfflineRequestQueue offlineRequestQueue})
Ensures the remoteProvider is a SupabaseProvider.

Properties

autoHydrate bool
Refetch results in the background from remote source when any request is made. Defaults to false.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
logger → Logger
User for low-level debugging. The logger name can be defined in the default constructor; it defaults to OfflineFirstRepository.
finalinherited
memoryCacheProvider → MemoryCacheProvider<SqliteModel>
The first data source to speed up otherwise taxing queries. Only caches specified models.
finalinherited
migrationManager → MigrationManager
All historical and new migrations are available to the mgiration manager.
finalinherited
offlineRequestQueue → RestOfflineRequestQueue
In most cases, this queue can be generated using clientQueue.
final
remoteProvider → SupabaseProvider
The type declaration is important here for the rare circumstances that require interfacting with SupabaseProvider's client directly.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sqliteProvider → SqliteProvider<SqliteModel>
The local data source utilized before every operation.
finalinherited
subscriptions Map<Type, Map<Query?, StreamController<List<TRepositoryModel>>>>
Internally-maintained stream controllers generated by subscribe.
finalinherited
supabaseRealtimeSubscriptions Map<Type, Map<PostgresChangeEvent, Map<Query, StreamController<List<TRepositoryModel>>>>>
Tracks the realtime stream controllers
final

Methods

applyPolicyToQuery(Query? query, {OfflineFirstDeletePolicy? delete, OfflineFirstGetPolicy? get, OfflineFirstUpsertPolicy? upsert}) → Query?
As some remote provider's may utilize an OfflineFirstPolicy from the request, this composes the policy to the query (such as in the providerArgs).
inherited
delete<TModel extends TRepositoryModel>(TModel instance, {OfflineFirstDeletePolicy policy = OfflineFirstDeletePolicy.optimisticLocal, Query? query}) Future<bool>
Remove a model from SQLite and the remoteProvider
exists<TModel extends TRepositoryModel>({Query? query}) Future<bool>
Check if a TModel is accessible locally. First checks if there's a matching query in memoryCacheProvider and then check sqliteProvider. Does not query remoteProvider.
inherited
get<TModel extends TRepositoryModel>({OfflineFirstGetPolicy policy = OfflineFirstGetPolicy.awaitRemoteWhenNoneExist, Query? query, bool seedOnly = false}) Future<List<TModel>>
Load association from SQLite first; if the TModel hasn't been loaded previously, fetch it from remoteProvider and hydrate SQLite. For available query providerArgs see remoteProvider#get SqliteProvider.get.
getAssociation<TModel extends TRepositoryModel>(Query query) Future<List<TModel>?>
Used exclusively by the OfflineFirstAdapter. If there are no results, returns null.
inherited
getBatched<TModel extends TRepositoryModel>({int batchSize = 50, OfflineFirstGetPolicy policy = OfflineFirstGetPolicy.awaitRemoteWhenNoneExist, Query? query, bool seedOnly = false}) Future<List<TModel>>
Get all results in series of batchSizes (defaults to 50). Useful for large queries or remote results.
inherited
hydrate<TModel extends TRepositoryModel>({bool deserializeSqlite = true, Query? query}) Future<List<TModel>>
Fetch and store results from remoteProvider into SQLite and the memory cache.
initialize() Future<void>
Prepare the environment for future repository functions. It is recommended to call this method within a StatefulWidget's initState to ensure it is only invoked once. It is not automatically invoked.
migrate() Future<void>
Update SQLite structure with only new migrations.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifySubscriptionsWithLocalData<TModel extends TRepositoryModel>({bool notifyWhenEmpty = true, Map<Query?, StreamController<List<TRepositoryModel>>>? subscriptionsByQuery}) Future<void>
Iterate through subscriptions after an upsert and notify any subscribe listeners.
queryFromSupabaseDeletePayload(Map<String, dynamic> payload, {required Map<String, RuntimeSupabaseColumnDefinition> supabaseDefinitions}) → Query
Supabase's realtime payload only returns unique columns; the instance must be discovered from these values so it can be deleted by all providers.
queryToPostgresChangeFilter<TModel extends TRepositoryModel>(Query query) → PostgresChangeFilter?
Convert a query to a PostgresChangeFilter for use with subscribeToRealtime.
reset() Future<void>
Destroys all local records - specifically, memoryCache and sqliteProvider's data sources.
storeRemoteResults<TModel extends TRepositoryModel>(List<TModel> models, {bool shouldNotify = true}) Future<List<TModel>>
Save response results to SQLite.
inherited
subscribe<TModel extends TRepositoryModel>({OfflineFirstGetPolicy policy = OfflineFirstGetPolicy.localOnly, Query? query}) Stream<List<TModel>>
Listen for streaming changes when the sqliteProvider is invoked. For example, whenever new data is acquired from remote, or data is upserted locally, or data is deleted locally, the stream will be notified with a local fetch of query.
inherited
subscribeToRealtime<TModel extends TRepositoryModel>({PostgresChangeEvent eventType = PostgresChangeEvent.all, OfflineFirstGetPolicy policy = OfflineFirstGetPolicy.alwaysHydrate, Query? query, String schema = 'public'}) Stream<List<TModel>>
Subscribes to realtime updates using Supabase channels. This will only work if your Supabase table has realtime enabled. Follow Supabase's documentation to setup your table.
toString() String
A string representation of this object.
inherited
upsert<TModel extends TRepositoryModel>(TModel instance, {OfflineFirstUpsertPolicy policy = OfflineFirstUpsertPolicy.optimisticLocal, Query? query}) Future<TModel>
Send a model to remoteProvider and hydrate.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

clientQueue({required DatabaseFactory databaseFactory, String databasePath = 'brick_offline_queue.sqlite', Set<String>? ignorePaths = const {'/auth/v1', '/storage/v1'}, Client? innerClient, Duration? processingInterval, List<int> reattemptForStatusCodes = const [400, 401, 403, 404, 405, 408, 409, 429, 500, 502, 503, 504], bool? serialProcessing, void onReattempt(Request request, int statusCode)?, void onRequestException(Request, Object)?}) → (RestOfflineQueueClient, RestOfflineRequestQueue)
This is a convenience method to create the basic offline client and queue. The client is used to add offline capabilities to SupabaseProvider; the queue is used to add offline to the repository.