count method

  1. @override
Future<int> count({
  1. String? userId,
  2. Where? where,
})
override

Returns the number of entries in the repository.

Implementation

@override
Future<int> count({String? userId, Where? where}) async {
  var query = userId != null
      ? _collectionReference.where(Model.userIdKey, isEqualTo: userId)
      : _collectionReference;

  if (where != null) {
    query = query.where(
      where.field,
      isEqualTo: where.isEqualTo,
      isNotEqualTo: where.isNotEqualTo,
      isLessThan: where.isLessThan,
      isGreaterThan: where.isGreaterThan,
      isLessThanOrEqualTo: where.isLessThanOrEqualTo,
      isGreaterThanOrEqualTo: where.isGreaterThanOrEqualTo,
      arrayContains: where.arrayContains,
      arrayContainsAny: where.arrayContainsAny,
      whereIn: where.whereIn,
      whereNotIn: where.whereNotIn,
      isNull: where.isNull,
    );
  }

  return query.count().get().then((value) => value.count ?? 0);
}