deleteAll method

Future<SqlStatementResult> deleteAll()

Deletes rows in the table.

client.table('person').selectWhere({'id': 1});

Implementation

Future<SqlStatementResult> deleteAll() {
  if ((_orderBy?.isNotEmpty ?? false) || _offset != null || _limit != null) {
    throw StateError(
      'DELETE statement doesnt support ORDER BY, OFFSET, or LIMIT ',
    );
  }
  final b = SqlSourceBuilder();
  b.write('DELETE FROM ');
  b.identifier(_tableName);

  final where = _where ?? const <SqlStatement>[];
  if (where.isNotEmpty) {
    b.write(' WHERE ');
    var comma = false;
    for (var sqlSource in where) {
      if (comma) {
        b.write(', ');
      }
      comma = true;
      b.write(sqlSource.value);
      b.arguments.addAll(sqlSource.arguments);
    }
  }

  final sqlSource = b.build();
  return _client.execute(sqlSource.value, sqlSource.arguments);
}