countElementsOf<T> method
Counts rows of T, optionally filtered by afterWhere and whereArgs.
expression: expression passed toCOUNT(...); defaults to'*'. Use'DISTINCT column'to count distinct values of a column.
Throws DatabaseException if the entity table does not exist.
Implementation
Future<int> countElementsOf<T>({
String expression = '*',
String? afterWhere,
List<Object?>? whereArgs,
}) async {
final List<Map<String, Object?>> rows = await _selectWhere(
'count($expression) AS countElement',
quoteIdentifier(_tableFor<T>()),
afterWhere,
whereArgs,
);
return (rows.first['countElement'] as int?) ?? 0;
}