countRows method
SqlRead<int>
countRows(
- SqlTable<
Object?> from, { - List<
SqlJoin> joins = const <SqlJoin>[], - SqlPredicate? where,
Counts rows produced by from, optional relational joins, and where.
This compiles COUNT(*), so joined duplicates count as separate relation
rows and an empty relation returns zero. Ordering and pagination are
deliberately not part of this operation, and Odroe never runs it
implicitly.
Implementation
SqlRead<int> countRows(
SqlTable<Object?> from, {
List<SqlJoin> joins = const <SqlJoin>[],
SqlPredicate? where,
}) {
final tables = _validateJoins(from, joins);
final aliases = _selectAliases(tables, qualified: joins.isNotEmpty);
final builder = _BoundSqlBuilder(dialect)
..write('SELECT COUNT(*) AS ')
..write(dialect.quoteIdentifier(_countColumn.name));
_writeSource(builder, from, joins, tables, aliases);
_writeWhere(builder, tables, aliases, where);
return SqlRead<int>._(
builder.build(kind: SqlStatementKind.rowReturning),
_decodeCount,
);
}