delete method

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

Implementation

@override
Future<int> delete({
  Filter Function(TMeta t)? where,
  bool? useIsolate,
  bool all = false,
}) async {
  assert(
    all || where != null,
    'Either provide where query or specify all = true to delete all.',
  );
  final db = await dbContext.database;
  final formattedQuery = where != null
      ? await whereString(
          where,
          useIsolate: useIsolate,
        )
      : null;
  return db.transaction<int>((txn) async {
    final batch = txn.batch()
      ..delete(
        t.tableName,
        where: formattedQuery?.filter,
        whereArgs: formattedQuery?.whereArgs,
      );
    final result =
        await batch.commit(noResult: false, continueOnError: false);
    if (result.isEmpty) {
      return 0;
    }
    final res = result[0];
    if (res is int) {
      return res;
    }
    return 0;
  });
}