fetchAll method

Future<List<EntryObject>> fetchAll({
  1. required String category,
  2. bool forUpdate = false,
  3. int? limit,
  4. Map<String, dynamic>? tagFilter,
  5. bool isJson = false,
  6. String? orderBy,
  7. bool? descending,
})

Fetches all records matching a category and tag filter.

Throws an AskarSessionException if the session is closed. Returns a list of EntryObject containing the fetched records.

Implementation

Future<List<EntryObject>> fetchAll({
  required String category,
  bool forUpdate = false,
  int? limit,
  Map<String, dynamic>? tagFilter,
  bool isJson = false,
  String? orderBy,
  bool? descending,
}) async {
  _throwOnNullHandle('Cannot fetch all from a closed session');

  EntryListHandle? entryListHandle;

  try {
    final fetchAllResult = await askarSessionFetchAll(
      handle!,
      category,
      forUpdate: forUpdate,
      tagFilter: tagFilter,
      limit: limit,
    );

    if (!fetchAllResult.errorCode.isSuccess()) {
      return [];
    }

    entryListHandle = fetchAllResult.value;

    return EntryList(handle: entryListHandle).toArray(valuesAreJson: isJson);
  } catch (e) {
    throw AskarSessionException('Failed to fetch entries: $e');
  } finally {
    if (entryListHandle != null) {
      entryListHandle.free();
    }
  }
}