get<_Model extends _RepositoryModel> method

  1. @override
Future<List<_Model>> get<_Model extends _RepositoryModel>({
  1. Query? query,
  2. bool alwaysHydrate = false,
  3. bool hydrateUnexisting = true,
  4. bool requireRemote = false,
  5. bool seedOnly = false,
})

Load association from SQLite first; if the _Model hasn't been loaded previously, fetch it from remoteProvider and hydrate SQLite. For available query providerArgs see remoteProvider#get SqliteProvider.get.

alwaysHydrate ensures data is fetched from the remoteProvider for each invocation. This often negatively affects performance when enabled. Defaults to false.

hydrateUnexisting retrieves from the remoteProvider if the query returns no results from SQLite. If an empty response can be expected (such as a search page), set to false. Defaults to true.

requireRemote ensures data must be updated from the remoteProvider before returning if the app is online. An empty array will be returned if the app is offline. Defaults to false.

seedOnly does not load data from SQLite after inserting records. Association queries can be expensive for large datasets, making deserialization a significant hit when the result is ignorable (e.g. eager loading). Defaults to false.

Implementation

@override
Future<List<_Model>> get<_Model extends _RepositoryModel>({
  Query? query,
  bool alwaysHydrate = false,
  bool hydrateUnexisting = true,
  bool requireRemote = false,
  bool seedOnly = false,
}) async {
  query = (query ?? Query()).copyWith(action: QueryAction.get);
  logger.finest('#get: $_Model $query');

  if (memoryCacheProvider.canFind<_Model>(query)) {
    final memoryCacheResults = memoryCacheProvider.get<_Model>(query: query, repository: this);

    if (memoryCacheResults?.isNotEmpty ?? false) return memoryCacheResults!;
  }

  final modelExists = await exists<_Model>(query: query);
  if (requireRemote || (hydrateUnexisting && !modelExists)) {
    return await hydrate<_Model>(query: query, deserializeSqlite: !seedOnly);
  } else if (alwaysHydrate) {
    // start round trip for fresh data
    // ignore: unawaited_futures
    hydrate<_Model>(query: query, deserializeSqlite: !seedOnly);
  }

  return await sqliteProvider
      .get<_Model>(query: query, repository: this)
      // cache this query
      .then((m) => memoryCacheProvider.hydrate<_Model>(m));
}