count method

Selectable<int> count({
  1. Expression<bool> where(
    1. Tbl row
    )?,
})

Counts the rows in this table.

The optional where clause can be used to only count rows matching the condition, similar to SimpleSelectStatement.where.

The returned Selectable can be run once with Selectable.getSingle to get the count once, or be watched as a stream with Selectable.watchSingle.

Implementation

Selectable<int> count({Expression<bool> Function(Tbl row)? where}) {
  final count = countAll();
  final stmt = selectOnly()..addColumns([count]);
  if (where != null) {
    stmt.where(where(asDslTable));
  }

  return stmt.map((row) => row.read(count)!);
}