Class Query

Build a Query object.

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

Datastore Queries

Package

@google-cloud/datastore

Constructors

(constructor)(scope, kinds)

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

Constructs a new instance of the Query class

Parameters
NameDescription
scope Datastore | Transaction
kinds string[] | null

(constructor)(scope, namespace, kinds)

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

Constructs a new instance of the Query class

Parameters
NameDescription
scope Datastore | Transaction
namespace string | null
kinds string[]

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;

Set an ending cursor to a query.

Query Cursors

Parameter
NameDescription
end string | Buffer
Returns
TypeDescription
this

{Query}

filter(property, value)

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

filter(property, operator, value)

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

groupBy(fieldNames)

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

Group query results by a list of properties.

Parameter
NameDescription
fieldNames string | string[]
Returns
TypeDescription
this

{Query}

hasAncestor(key)

hasAncestor(key: Key): this;

Filter a query by ancestors.

Datastore Ancestor Filters

Parameter
NameDescription
key Key

Key object to filter by.

Returns
TypeDescription
this

{Query}

limit(n)

limit(n: number): this;

Set a limit on a query.

Query Limits

Parameter
NameDescription
n number

The number of results to limit the query to.

Returns
TypeDescription
this

{Query}

offset(n)

offset(n: number): this;

Set an offset on a query.

Query Offsets

Parameter
NameDescription
n number

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

Parameters
NameDescription
property string

The property to order by.

options OrderOptions

Options object.

Returns
TypeDescription
this

{Query}

run(options)

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

run(options, callback)

run(options: RunQueryOptions, callback: RunQueryCallback): void;
Parameters
NameDescription
options RunQueryOptions
callback RunQueryCallback
Returns
TypeDescription
void

run(callback)

run(callback: RunQueryCallback): void;
Parameter
NameDescription
callback RunQueryCallback
Returns
TypeDescription
void

runStream(options)

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

Run the query as a readable object stream.

Query#runStream

Parameter
NameDescription
options RunQueryStreamOptions

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

Parameter
NameDescription
fieldNames string | string[]

Properties to return from the matched entities.

Returns
TypeDescription
this

{Query}

start(start)

start(start: string | Buffer): this;

Set a starting cursor to a query.

Query Cursors

Parameter
NameDescription
start string | Buffer
Returns
TypeDescription
this

{Query}