class Query

Build a Query object.

Queries are built with {module:datastore#createQuery} and Transaction#createQuery.

Examples

Example 1

const {Datastore} = require('@google-cloud/datastore');
const datastore = new Datastore();
const query = datastore.createQuery('AnimalNamespace', 'Lion');

Constructors

new
Query(
scope?: Datastore | Transaction,
kinds?: string[] | null,
)
new
Query(
scope?: Datastore | Transaction,
namespace?: string | null,
kinds?: string[],
)

Properties

endVal:
string
| Buffer
| null
entityFilters: EntityFilter[]
filters: Filter[]
groupByVal: Array<{ }>
kinds: string[]
limitVal: number
optional
namespace: string | null
offsetVal: number
orders: Order[]
optional
scope: Datastore | Transaction
selectVal: Array<{ }>
startVal:
string
| Buffer
| null

Methods

end(end: string | Buffer): this

Set an ending cursor to a query.

filter(filter: EntityFilter): Query

Datastore allows querying on properties. Supported comparison operators are =, <, >, <=, >=, !=, HAS_ANCESTOR, IN and NOT_IN.

To filter by ancestors, see {module:datastore/query#hasAncestor}.

filter<T extends string>(
property: T,
value: AllowedFilterValueType<T>,
): Query
filter<T extends string>(
property: T,
operator: Operator,
value: AllowedFilterValueType<T>,
): Query
groupBy(fieldNames: string | string[]): this

Group query results by a list of properties.

hasAncestor(key: Key): this

Filter a query by ancestors.

limit(n: number): this

Set a limit on a query.

offset(n: number): this

Set an offset on a query.

order(
property: string,
options?: OrderOptions,
): this

Sort the results by a property name in ascending or descending order. By default, an ascending sort order will be used.

run(options?: RunQueryOptions): Promise<RunQueryResponse>

Run the query.

run(
options: RunQueryOptions,
callback: RunQueryCallback,
): void
run(callback: RunQueryCallback): void
runStream(options?: RunQueryStreamOptions): import("stream").Transform

Run the query as a readable object stream.

select(fieldNames: string | string[]): this

Retrieve only select properties from the matched entities.

Queries that select a subset of properties are called Projection Queries.

start(start: string | Buffer): this

Set a starting cursor to a query.

See