Class: Google::Cloud::Firestore::AggregateQuery
- Inherits:
-
Object
- Object
- Google::Cloud::Firestore::AggregateQuery
- Defined in:
- lib/google/cloud/firestore/aggregate_query.rb
Overview
AggregateQuery
An aggregate query can be used to fetch aggregate values (ex: count) for a query
Instances of this class are immutable. All methods that refine the aggregate query return new instances.
Instance Method Summary collapse
-
#add_count(aggregate_alias: nil) ⇒ AggregateQuery
Adds a count aggregate.
-
#get {|snapshot| ... } ⇒ Enumerator<AggregateQuerySnapshot>
Retrieves aggregate snapshot for the query.
Instance Method Details
#add_count(aggregate_alias: nil) ⇒ AggregateQuery
Adds a count aggregate.
108 109 110 111 112 113 114 115 116 |
# File 'lib/google/cloud/firestore/aggregate_query.rb', line 108 def add_count aggregate_alias: nil aggregate_alias ||= ALIASES[:count] new_aggregates = @aggregates.dup new_aggregates << StructuredAggregationQuery::Aggregation.new( count: StructuredAggregationQuery::Aggregation::Count.new, alias: aggregate_alias ) AggregateQuery.start query, new_aggregates, parent_path, client end |
#get {|snapshot| ... } ⇒ Enumerator<AggregateQuerySnapshot>
Retrieves aggregate snapshot for the query.
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/google/cloud/firestore/aggregate_query.rb', line 141 def get ensure_service! return enum_for :get unless block_given? responses = service.run_aggregate_query @parent_path, structured_aggregation_query responses.each do |response| next if response.result.nil? yield AggregateQuerySnapshot.from_run_aggregate_query_response response end end |