hydrate<_Model extends _RepositoryModel> method

  1. @protected
Future<List<_Model>> hydrate<_Model extends _RepositoryModel>({
  1. bool deserializeSqlite = true,
  2. Query? query,
})

Fetch and store results from remoteProvider into SQLite and the memory cache.

deserializeSqlite loads data from SQLite after they've been inserted. Association queries can be expensive for large datasets, making deserialization a significant hit when the result is ignorable. Defaults to true.

Implementation

@protected
Future<List<_Model>> hydrate<_Model extends _RepositoryModel>({
  bool deserializeSqlite = true,
  Query? query,
}) async {
  try {
    logger.finest('#hydrate: $_Model $query');
    final modelsFromRemote = await remoteProvider.get<_Model>(query: query, repository: this);

    if (modelsFromRemote != null) {
      final modelsIntoSqlite = await storeRemoteResults<_Model>(modelsFromRemote);
      final modelsIntoMemory = memoryCacheProvider.hydrate<_Model>(modelsIntoSqlite);

      if (!deserializeSqlite) return modelsIntoMemory;
    }

    return await sqliteProvider
        .get<_Model>(query: query, repository: this)
        .then((d) => memoryCacheProvider.hydrate<_Model>(d));
  } on ClientException catch (e) {
    logger.warning('#hydrate client failure: $e');
  } on SocketException catch (e) {
    logger.warning('#hydrate socket failure: $e');
  }

  return <_Model>[];
}