Firestore in Datastore mode API - Class Google::Cloud::Datastore::Dataset::AggregateQueryResults (v2.9.0)

Reference documentation and code samples for the Firestore in Datastore mode API class Google::Cloud::Datastore::Dataset::AggregateQueryResults.

AggregateQueryResults

An AggregateQueryResult object is a representation for a result of an AggregateQuery or a GqlQuery.

Inherits

  • Object

Example

require "google/cloud/datastore"

datastore = Google::Cloud::Datastore.new

query = Google::Cloud::Datastore::Query.new
query.kind("Task")
     .where("done", "=", false)

Create an aggregate query
aggregate_query = query.aggregate_query
                       .add_count

aggregate_query_results = dataset.run_aggregation aggregate_query
puts aggregate_query_results.get

Methods

#get

def get(aggregate_alias = nil) -> Integer, Float, nil

Retrieves the aggregate data.

if the aggregate_alias does not exist.

Parameter
  • aggregate_alias (String) — The alias used to access the aggregate value. For an AggregateQuery with a single aggregate field, this parameter can be omitted.
Returns
  • (Integer, Float, nil) — The aggregate value. Returns nil
Examples
require "google/cloud/datastore"

datastore = Google::Cloud::Datastore.new

query = Google::Cloud::Datastore::Query.new
query.kind("Task")
     .where("done", "=", false)

Create an aggregate query
aggregate_query = query.aggregate_query
                       .add_count

aggregate_query_results = dataset.run_aggregation aggregate_query
puts aggregate_query_results.get

Alias an aggregate query

require "google/cloud/datastore"

datastore = Google::Cloud::Datastore.new

query = Google::Cloud::Datastore::Query.new
query.kind("Task")
     .where("done", "=", false)

Create an aggregate query
aggregate_query = query.aggregate_query
                       .add_count aggregate_alias: 'total'

aggregate_query_results = dataset.run_aggregation aggregate_query
puts aggregate_query_results.get('total')

#read_time

def read_time() -> 

Read timestamp the query was done on the database at.

Returns
  • — Google::Protobuf::Timestamp