delete method

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

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.');
  final db = await dbContext.database;
  final formattedQuery = where != null
      ? await whereString(
          where,
          useIsolate,
        )
      : null;
  return await db.transaction<int>((txn) async {
    var batch = txn.batch();
    batch.delete(
      t.tableName,
      where: formattedQuery?.filter,
      whereArgs: formattedQuery?.whereArgs,
    );
    var 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;
  });
}