countElementsOf<T> method

Future<int> countElementsOf<T>({
  1. String expression = '*',
  2. String? afterWhere,
  3. List<Object?>? whereArgs,
})

Counts rows of T, optionally filtered by afterWhere and whereArgs.

  • expression: expression passed to COUNT(...); 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;
}