Class Query

Build a Query object.

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

[Datastore Queries]http://goo.gl/Cag0r6

Package

@google-cloud/datastore!

Constructors

(constructor)(scope, kinds)

constructor(scope?: Datastore | Transaction, kinds?: string[] | null);

Constructs a new instance of the Query class

Parameters
TypeNameDescription
Datastore | Transactionscope
string[] | nullkinds

(constructor)(scope, namespace, kinds)

constructor(scope?: Datastore | Transaction, namespace?: string | null, kinds?: string[]);

Constructs a new instance of the Query class

Parameters
TypeNameDescription
Datastore | Transactionscope
string | nullnamespace
string[]kinds

Properties

endVal

endVal: string | Buffer | null;
Property Value
TypeDescription
string | Buffer | null

filters

filters: Filter[];
Property Value
TypeDescription
Filter[]

groupByVal

groupByVal: Array<{}>;
Property Value
TypeDescription
Array<{}>

kinds

kinds: string[];
Property Value
TypeDescription
string[]

limitVal

limitVal: number;
Property Value
TypeDescription
number

namespace

namespace?: string | null;
Property Value
TypeDescription
string | null

offsetVal

offsetVal: number;
Property Value
TypeDescription
number

orders

orders: Order[];
Property Value
TypeDescription
Order[]

scope

scope?: Datastore | Transaction;
Property Value
TypeDescription
Datastore | Transaction

selectVal

selectVal: Array<{}>;
Property Value
TypeDescription
Array<{}>

startVal

startVal: string | Buffer | null;
Property Value
TypeDescription
string | Buffer | null

Methods

end(end)

end(end: string | Buffer): this;
Parameter
TypeNameDescription
string | Bufferend
Returns
TypeDescription
this

{Query}

filter(property, value)

filter(property: string, value: {}): Query;
Parameters
TypeNameDescription
stringproperty
{}value
Returns
TypeDescription
Query

filter(property, operator, value)

filter(property: string, operator: Operator, value: {}): Query;
Parameters
TypeNameDescription
stringproperty
Operatoroperator
{}value
Returns
TypeDescription
Query

groupBy(fieldNames)

groupBy(fieldNames: string | string[]): this;

Group query results by a list of properties.

Parameter
TypeNameDescription
string | string[]fieldNames
Returns
TypeDescription
this

{Query}

hasAncestor(key)

hasAncestor(key: Key): this;
Parameter
TypeNameDescription
Keykey

Key object to filter by.

Returns
TypeDescription
this

{Query}

limit(n)

limit(n: number): this;
Parameter
TypeNameDescription
numbern

The number of results to limit the query to.

Returns
TypeDescription
this

{Query}

offset(n)

offset(n: number): this;
Parameter
TypeNameDescription
numbern

The offset to start from after the start cursor.

Returns
TypeDescription
this

{Query}

order(property, options)

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.

[Datastore Sort Orders]https://cloud.google.com/datastore/docs/concepts/queries#datastore-ascending-sort-nodejs

Parameters
TypeNameDescription
stringproperty

The property to order by.

OrderOptionsoptions

Options object.

Returns
TypeDescription
this

{Query}

run(options)

run(options?: RunQueryOptions): Promise<RunQueryResponse>;
Parameter
TypeNameDescription
RunQueryOptionsoptions
Returns
TypeDescription
Promise<RunQueryResponse>

run(options, callback)

run(options: RunQueryOptions, callback: RunQueryCallback): void;
Parameters
TypeNameDescription
RunQueryOptionsoptions
RunQueryCallbackcallback
Returns
TypeDescription
void

run(callback)

run(callback: RunQueryCallback): void;
Parameter
TypeNameDescription
RunQueryCallbackcallback
Returns
TypeDescription
void

runStream(options)

runStream(options?: RunQueryStreamOptions): import("stream").Transform;

Run the query as a readable object stream.

Query#runStream

Parameter
TypeNameDescription
RunQueryStreamOptionsoptions

Optional configuration. See for a complete list of options.

Returns
TypeDescription
import("stream").internal.Transform

{stream}

select(fieldNames)

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

Retrieve only select properties from the matched entities.

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

[Projection Queries]https://cloud.google.com/datastore/docs/concepts/projectionqueries

Parameter
TypeNameDescription
string | string[]fieldNames

Properties to return from the matched entities.

Returns
TypeDescription
this

{Query}

start(start)

start(start: string | Buffer): this;
Parameter
TypeNameDescription
string | Bufferstart
Returns
TypeDescription
this

{Query}