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
Type Name Description
Datastore | Transaction
scope
string[] | null
kinds

(constructor)(scope, namespace, kinds)

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

Constructs a new instance of the Query class

Parameters
Type Name Description
Datastore | Transaction
scope
string | null
namespace
string[]
kinds

Properties

endVal

  endVal 
 : 
  
 string 
  
 | 
  
 Buffer 
  
 | 
  
 null 
 ; 
 
Property Value
Type Description
string | Buffer | null

filters

  filters 
 : 
  
 Filter 
 []; 
 
Property Value
Type Description
Filter []

groupByVal

  groupByVal 
 : 
  
 Array 
< {}>; 
 
Property Value
Type Description
Array <{}>

kinds

  kinds 
 : 
  
 string 
 []; 
 
Property Value
Type Description
string[]

limitVal

  limitVal 
 : 
  
 number 
 ; 
 
Property Value
Type Description
number

namespace

  namespace 
 ?: 
  
 string 
  
 | 
  
 null 
 ; 
 
Property Value
Type Description
string | null

offsetVal

  offsetVal 
 : 
  
 number 
 ; 
 
Property Value
Type Description
number

orders

  orders 
 : 
  
 Order 
 []; 
 
Property Value
Type Description
Order []

scope

  scope 
 ?: 
  
 Datastore 
  
 | 
  
 Transaction 
 ; 
 
Property Value
Type Description
Datastore | Transaction

selectVal

  selectVal 
 : 
  
 Array 
< {}>; 
 
Property Value
Type Description
Array <{}>

startVal

  startVal 
 : 
  
 string 
  
 | 
  
 Buffer 
  
 | 
  
 null 
 ; 
 
Property Value
Type Description
string | Buffer | null

Methods

end(end)

  end 
 ( 
 end 
 : 
  
 string 
  
 | 
  
 Buffer 
 ) 
 : 
  
 this 
 ; 
 
Parameter
Type Name Description
string | Buffer
end
Returns
Type Description
this

{Query}

filter(property, value)

  filter 
 ( 
 property 
 : 
  
 string 
 , 
  
 value 
 : 
  
 {}) 
 : 
  
 Query 
 ; 
 
Parameters
Type Name Description
string
property
{}
value
Returns
Type Description
Query

filter(property, operator, value)

  filter 
 ( 
 property 
 : 
  
 string 
 , 
  
 operator 
 : 
  
 Operator 
 , 
  
 value 
 : 
  
 {}) 
 : 
  
 Query 
 ; 
 
Parameters
Type Name Description
string
property
Operator
operator
{}
value
Returns
Type Description
Query

groupBy(fieldNames)

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

Group query results by a list of properties.

Parameter
Type Name Description
string | string[]
fieldNames
Returns
Type Description
this

{Query}

hasAncestor(key)

  hasAncestor 
 ( 
 key 
 : 
  
 Key 
 ) 
 : 
  
 this 
 ; 
 

Filter a query by ancestors.

[Datastore Ancestor Filters] https://cloud.google.com/datastore/docs/concepts/queries#datastore-ancestor-query-nodejs

Parameter
Type Name Description
Key
key

Key object to filter by.

Returns
Type Description
this

{Query}

limit(n)

  limit 
 ( 
 n 
 : 
  
 number 
 ) 
 : 
  
 this 
 ; 
 
Parameter
Type Name Description
number
n

The number of results to limit the query to.

Returns
Type Description
this

{Query}

offset(n)

  offset 
 ( 
 n 
 : 
  
 number 
 ) 
 : 
  
 this 
 ; 
 
Parameter
Type Name Description
number
n

The offset to start from after the start cursor.

Returns
Type Description
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
Type Name Description
string
property

The property to order by.

OrderOptions
options

Options object.

Returns
Type Description
this

{Query}

run(options)

  run 
 ( 
 options 
 ?: 
  
 RunQueryOptions 
 ) 
 : 
  
 Promise<RunQueryResponse> 
 ; 
 
Parameter
Type Name Description
RunQueryOptions
options
Returns
Type Description
Promise < RunQueryResponse >

run(options, callback)

  run 
 ( 
 options 
 : 
  
 RunQueryOptions 
 , 
  
 callback 
 : 
  
 RunQueryCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameters
Type Name Description
RunQueryOptions
options
RunQueryCallback
callback
Returns
Type Description
void

run(callback)

  run 
 ( 
 callback 
 : 
  
 RunQueryCallback 
 ) 
 : 
  
 void 
 ; 
 
Parameter
Type Name Description
RunQueryCallback
callback
Returns
Type Description
void

runStream(options)

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

Run the query as a readable object stream.

Query#runStream

Parameter
Type Name Description
RunQueryStreamOptions
options

Optional configuration. See for a complete list of options.

Returns
Type Description
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
Type Name Description
string | string[]
fieldNames

Properties to return from the matched entities.

Returns
Type Description
this

{Query}

start(start)

  start 
 ( 
 start 
 : 
  
 string 
  
 | 
  
 Buffer 
 ) 
 : 
  
 this 
 ; 
 
Parameter
Type Name Description
string | Buffer
start
Returns
Type Description
this

{Query}

Create a Mobile Website
View Site in Mobile | Classic
Share by: