delete method

  1. @override
Future<int> delete({
  1. Filter where(
    1. TMeta t
    )?,
  2. bool? useIsolate,
  3. bool? all,
})

Implementation

@override
Future<int> delete({
  final Filter Function(TMeta t)? where,
  final bool? useIsolate,
  final bool? all,
}) async {
  assert(all == true || where != null,
      'Either provide where query or specify all = true to delete all.');

  Map<String, dynamic> items = await getItems() ?? {};
  if (where == null) {
    return items.length;
  }
  final filters = where(t).filters;
  final res = items.entries
      .where(
        (element) {
          return _where(element, filters);
        },
      )
      .map((e) => e.key)
      .toList();

  items.removeWhere((key, value) => res.contains(key));
  await (await prefs).setString(t.tableName, jsonEncode(items));
  return res.length;
}