delete method

Future delete({
  1. bool withRelatedItems = true,
  2. ConditionQuery where(
    1. T e
    )?,
})

Delete entries from this table, if where is null it will delete every entry, otherwise it delete only matching entries.

Implementation

Future delete({
  bool withRelatedItems = true,
  ConditionQuery Function(T e)? where,
}) async {
  if (!withRelatedItems) {
    if (where != null) {
      var ids = (await select(where: where, desiredFields: (s) => [s.id]))
          .map((e) => e.id.value!);

      int result = 0;
      var db = await _initializeDB();
      result = await db
          .delete(tableName, where: "$idColumnName IN ?", whereArgs: [ids]);
      return result;
    } else {
      int result = 0;
      var db = await _initializeDB();
      result = await db.delete(
        tableName,
      );
      return result;
    }
  } else {
    for (var entry in await select(where: where)) {
      await deleteEntry(entry);
    }
  }
}