@google-cloud/datastore
Version:
Cloud Datastore Client Library for Node.js
165 lines (164 loc) • 5.04 kB
TypeScript
import { Query } from './index';
import { RunQueryOptions, RunQueryResponse } from './query';
import { RequestCallback } from './request';
declare const AGGREGATE_QUERY: unique symbol;
/**
* An AggregateQuery is a class that can be used to obtain results from an
* aggregate query request.
*
* @see {@link https://cloud.google.com/datastore/docs/aggregation-queries| Aggregation queries Reference}
*
* @class
*/
declare class AggregateQuery {
type: symbol;
aggregations: Array<AggregateField>;
query: Query | undefined;
/**
* Build an AggregateQuery object.
*
* @param {Query} query A Query object
*/
constructor(query: Query);
/**
* Add a `count` aggregate query to the list of aggregations.
*
* @param {string} alias The label used in the results to describe this
* aggregate field when a query is run.
* @returns {AggregateQuery}
*/
count(alias?: string): AggregateQuery;
/**
* Add a `sum` aggregate query to the list of aggregations.
*
* @param {string} property The property to use for the sum calculation.
* @param {string} alias The label used in the results to describe this
* aggregate field when a query is run.
* @returns {AggregateQuery}
*/
sum(property: string, alias?: string): AggregateQuery;
/**
* Add a `average` aggregate query to the list of aggregations.
*
* @param {string} property The property to use for the average calculation.
* @param {string} alias The label used in the results to describe this
* aggregate field when a query is run.
* @returns {AggregateQuery}
*/
average(property: string, alias?: string): AggregateQuery;
/**
* Add a custom aggregation to the list of aggregations.
*
* @param {AggregateField} aggregation The aggregate field to perform the
* aggregation query over.
* @returns {AggregateQuery}
*/
addAggregation(aggregation: AggregateField): AggregateQuery;
/**
* Add a list of custom aggregations to the list of aggregations.
*
* @param {AggregateField[]} aggregations The aggregate fields to perform the
* aggregation query over.
* @returns {AggregateQuery}
*/
addAggregations(aggregations: AggregateField[]): AggregateQuery;
/**
* Run the aggregation query and return the results.
*
* @param {RunQueryOptions | RequestCallback} [optionsOrCallback]
* @param {function} cb The callback function.
* @returns {void | Promise<RunQueryResponse>}
*/
run(optionsOrCallback?: RunQueryOptions | RequestCallback, cb?: RequestCallback): void | Promise<RunQueryResponse>;
/**
* Get the proto for the list of aggregations.
*
*/
toProto(): any;
}
/**
* An AggregateField is a class that contains data that defines an aggregation.
*
*/
declare abstract class AggregateField {
alias_?: string;
/**
* Gets a copy of the Count aggregate field.
*
* @returns {Count}
*/
static count(): Count;
/**
* Gets a copy of the Sum aggregate field.
*
* @param {string} property The property to use for the average calculation.
* @returns {Sum}
*/
static sum(property: string): Sum;
/**
* Gets a copy of the Average aggregate field.
*
* @param {string} property The property to use for the average calculation.
* @returns {Average}
*/
static average(property: string): Average;
/**
* Sets the alias on the aggregate field that should be used.
*
* @param {string} alias The label used in the results to describe this
* aggregate field when a query is run.
* @returns {AggregateField}
*/
alias(alias?: string): AggregateField;
/**
* Gets the proto for the aggregate field.
*
*/
abstract toProto(): any;
}
/**
* A Count is a class that contains data that defines a Count aggregation.
*
*/
declare class Count extends AggregateField {
/**
* Gets the proto for the count aggregate field.
*
*/
toProto(): any;
}
/**
* A PropertyAggregateField is a class that contains data that defines any
* aggregation that is performed on a property.
*
*/
declare abstract class PropertyAggregateField extends AggregateField {
property_: string;
abstract operator: string;
/**
* Build a PropertyAggregateField object.
*
* @param {string} property The property to aggregate over.
*/
constructor(property_: string);
/**
* Gets the proto for the property aggregate field.
*
*/
toProto(): any;
}
/**
* A Sum is a class that contains data that defines a Sum aggregation.
*
*/
declare class Sum extends PropertyAggregateField {
operator: string;
}
/**
* An Average is a class that contains data that defines an Average aggregation.
*
*/
declare class Average extends PropertyAggregateField {
operator: string;
}
export { AggregateField, AggregateQuery, AGGREGATE_QUERY };