delete method

Future<int> delete(
  1. {@required String table,
  2. @required String where,
  3. bool verbose = false}
)

Delete some datapoints from the database

Implementation

Future<int> delete(
    {@required String table,
    @required String where,
    bool verbose = false}) async {
  /// [table] is the table to use and [where] the sql where clause
  ///
  /// Returns a future with a count of the deleted rows
  var deleted = 0;
  await _mutex.synchronized(() async {
    if (!_isReady) {
      throw DatabaseNotReady();
    }
    try {
      final timer = Stopwatch()..start();
      final q = 'DELETE FROM $table WHERE $where';
      await _db.transaction((txn) async {
        deleted = await txn.rawDelete(q);
      });
      timer.stop();
      _changeFeedController.sink.add(DatabaseChangeEvent(
          type: DatabaseChange.delete,
          value: deleted,
          query: q,
          table: table,
          executionTime: timer.elapsedMicroseconds));
      if (verbose) {
        final msg = "$q in ${timer.elapsedMilliseconds} ms";
        print(msg);
      }
      return deleted;
    } catch (e) {
      rethrow;
    }
  });
  return deleted;
}