count method

  1. @override
Future<int> count({
  1. Filter filter = Filter.empty,
})

Returns the count of all elements that match filter.

Implementation

@override
Future<int> count({Filter filter = Filter.empty}) async {
  return await find(postgresql).runTransaction((context) async {
    // TODO aggregates should be abstract
    final result = await dataRelation.select(context, [
      PostgresqlRawExpression(RawSql('COUNT(*) as "count"')),
    ], filter: filter);
    return result.firstOrNull?['count'] ?? 0;
  });
}