Constructor

DatastoreRequest

new DatastoreRequest()

Methods

createReadStream

createReadStream(keys, options)

Retrieve the entities as a readable object stream.

Parameter

keys

(Key or Array of Key)

Datastore key object(s).

options

Optional

object

Optional configuration. See Datastore#get for a complete list of options.

Throws

Error 

If at least one Key object is not provided.

Example

const keys = [
  datastore.key(['Company', 123]),
  datastore.key(['Product', 'Computer'])
];

datastore.createReadStream(keys)
  .on('error', (err) =>  {})
  .on('data', (entity) => {
    // entity is an entity object.
  })
  .on('end', () => {
    // All entities retrieved.
  });

runQueryStream

runQueryStream(query, options)

Get a list of entities as a readable object stream.

See Datastore#runQuery for a list of all available options.

Parameter

query

Query

Query object.

options

Optional

object

Optional configuration.

Values in options have the following properties:

Parameter

gaxOptions

Optional

object

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.

Example

datastore.runQueryStream(query)
  .on('error', console.error)
  .on('data', (entity) => {
    // Access the Key object for this entity.
    const key = entity[datastore.KEY];
  })
  .on('info', (info) => {})
  .on('end', () => {
    // All entities retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
datastore.runQueryStream(query)
  .on('data', (entity) => {
    this.end();
  });