Class: Google::Cloud::Datastore::AggregateQuery
- Inherits:
-
Object
- Object
- Google::Cloud::Datastore::AggregateQuery
- Defined in:
- lib/google/cloud/datastore/aggregate_query.rb
Overview
AggregateQuery
An aggregate query can be used to fetch aggregate values (ex: count) for a query
Instance Method Summary collapse
-
#add_avg(name, aggregate_alias: nil) ⇒ AggregateQuery
Adds an average aggregate.
-
#add_count(aggregate_alias: nil) ⇒ AggregateQuery
Adds a count aggregate.
-
#add_sum(name, aggregate_alias: nil) ⇒ AggregateQuery
Adds a sum aggregate.
Instance Method Details
#add_avg(name, aggregate_alias: nil) ⇒ AggregateQuery
Adds an average aggregate.
228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/google/cloud/datastore/aggregate_query.rb', line 228 def add_avg name, aggregate_alias: nil aggregate_alias ||= DEFAULT_AVG_AGGREGATE_ALIAS @grpc.aggregations << Google::Cloud::Datastore::V1::AggregationQuery::Aggregation.new( avg: Google::Cloud::Datastore::V1::AggregationQuery::Aggregation::Avg.new( property: Google::Cloud::Datastore::V1::PropertyReference.new( name: name ) ), alias: aggregate_alias ) self end |
#add_count(aggregate_alias: nil) ⇒ AggregateQuery
Adds a count aggregate.
124 125 126 127 128 129 130 131 132 |
# File 'lib/google/cloud/datastore/aggregate_query.rb', line 124 def add_count aggregate_alias: nil aggregate_alias ||= DEFAULT_COUNT_AGGREGATE_ALIAS @grpc.aggregations << Google::Cloud::Datastore::V1::AggregationQuery::Aggregation.new( count: Google::Cloud::Datastore::V1::AggregationQuery::Aggregation::Count.new, alias: aggregate_alias ) self end |
#add_sum(name, aggregate_alias: nil) ⇒ AggregateQuery
Adds a sum aggregate.
174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/google/cloud/datastore/aggregate_query.rb', line 174 def add_sum name, aggregate_alias: nil aggregate_alias ||= DEFAULT_SUM_AGGREGATE_ALIAS @grpc.aggregations << Google::Cloud::Datastore::V1::AggregationQuery::Aggregation.new( sum: Google::Cloud::Datastore::V1::AggregationQuery::Aggregation::Sum.new( property: Google::Cloud::Datastore::V1::PropertyReference.new( name: name ) ), alias: aggregate_alias ) self end |