destructiveLocalSyncFromRemote<TModel extends T> method

Future<List<TModel>> destructiveLocalSyncFromRemote<TModel extends T>({
  1. Query? query,
})

When invoked, local instances that exist in sqliteProvider and memoryCacheProvider but do not exist in the remoteProvider are destroyed. The data from the remoteProvider should not be paginated and must be complete from a single request.

Implementation

Future<List<TModel>> destructiveLocalSyncFromRemote<TModel extends T>({Query? query}) async {
  query = (query ?? Query()).copyWith(action: QueryAction.get);
  logger.finest('#get: $TModel $query');

  final remoteResults = await remoteProvider.get<TModel>(query: query, repository: this);
  final localResults = await sqliteProvider.get<TModel>(query: query, repository: this);
  final toDelete = localResults.where((r) => !remoteResults.contains(r));

  for (final deletableModel in toDelete) {
    await sqliteProvider.delete(deletableModel);
    memoryCacheProvider.delete(deletableModel);
  }

  return await storeRemoteResults<TModel>(remoteResults);
}