method Query.prototype.run
Query.prototype.run(options?: RunQueryOptions): Promise<RunQueryResponse>

Run the query.

Examples

Example 1

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

query.run((err, entities, info) => {
  // entities = An array of records.

  // Access the Key object for an entity.
  const firstEntityKey = entities[0][datastore.KEY];
});

//-
// A keys-only query returns just the keys of the result entities instead
of
// the entities themselves, at lower latency and cost.
//-
query.select('__key__');

query.run((err, entities) => {
  const keys = entities.map((entity) => {
    return entity[datastore.KEY];
  });
});

//-
// If the callback is omitted, we'll return a Promise.
//-
query.run().then((data) => {
  const entities = data[0];
});

Parameters

optional
options: RunQueryOptions

Optional configuration.

Return Type

Promise<RunQueryResponse>
Query.prototype.run(
options: RunQueryOptions,
callback: RunQueryCallback,
): void

Parameters

options: RunQueryOptions
callback: RunQueryCallback

Return Type

void
Query.prototype.run(callback: RunQueryCallback): void

Parameters

callback: RunQueryCallback

Return Type

void