count method
Counts matching rows in this scope, including limit and offset.
Executes one SELECT and decodes one integer, without reading model fields. Sorting is omitted because it does not change the number of rows. To get a total before pagination, count the unpaged immutable filter scope.
Implementation
Future<int> count() async {
final bindings = _bindings();
final source = 'FROM $_onlyTable${_where(bindings)}';
final sql = _limit == null && _offset == null
? 'SELECT COUNT(*) $source'
: 'SELECT COUNT(*) FROM (SELECT 1 $source${_pagination(bindings)}) AS "counted_rows"';
final result = await session.run(sql, parameters: bindings.values);
return decodeValue<int>(result.rows.single.single);
}