Constructor

DatastoreClient

new DatastoreClient(options)

Construct an instance of DatastoreClient.

Parameter

options

Optional

object

The configuration object. See the subsequent parameters for more details.

Properties

port

static

The port for this API service.

scopes

static

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

static

The DNS address for this API service.

Methods

allocateIds

allocateIds(request, options, callback) returns Promise

Allocates IDs for the given keys, which is useful for referencing an entity before it is inserted.

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing AllocateIdsResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing AllocateIdsResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const datastore = require('@google-cloud/datastore');

var client = new datastore.v1.DatastoreClient({
  // optional auth parameters.
});

var projectId = '';
var keys = [];
var request = {
  projectId: projectId,
  keys: keys,
};
client.allocateIds(request)
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

beginTransaction

beginTransaction(request, options, callback) returns Promise

Begins a new transaction.

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing BeginTransactionResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing BeginTransactionResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const datastore = require('@google-cloud/datastore');

var client = new datastore.v1.DatastoreClient({
  // optional auth parameters.
});

var projectId = '';
client.beginTransaction({projectId: projectId})
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

commit

commit(request, options, callback) returns Promise

Commits a transaction, optionally creating, deleting or modifying some entities.

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing CommitResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing CommitResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const datastore = require('@google-cloud/datastore');

var client = new datastore.v1.DatastoreClient({
  // optional auth parameters.
});

var projectId = '';
var mode = 'MODE_UNSPECIFIED';
var mutations = [];
var request = {
  projectId: projectId,
  mode: mode,
  mutations: mutations,
};
client.commit(request)
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

getProjectId

getProjectId(callback)

Return the project ID used by this class.

Parameter

callback

function(Error, string)

the callback to be called with the current project Id.

lookup

lookup(request, options, callback) returns Promise

Looks up entities by key.

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing LookupResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing LookupResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const datastore = require('@google-cloud/datastore');

var client = new datastore.v1.DatastoreClient({
  // optional auth parameters.
});

var projectId = '';
var keys = [];
var request = {
  projectId: projectId,
  keys: keys,
};
client.lookup(request)
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

reserveIds

reserveIds(request, options, callback) returns Promise

Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore.

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing ReserveIdsResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing ReserveIdsResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const datastore = require('@google-cloud/datastore');

var client = new datastore.v1.DatastoreClient({
  // optional auth parameters.
});

var projectId = '';
var keys = [];
var request = {
  projectId: projectId,
  keys: keys,
};
client.reserveIds(request)
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

rollback

rollback(request, options, callback) returns Promise

Rolls back a transaction.

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing RollbackResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing RollbackResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const datastore = require('@google-cloud/datastore');

var client = new datastore.v1.DatastoreClient({
  // optional auth parameters.
});

var projectId = '';
var transaction = '';
var request = {
  projectId: projectId,
  transaction: transaction,
};
client.rollback(request)
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

runQuery

runQuery(request, options, callback) returns Promise

Queries for entities.

Parameter

request

Object

The request object that will be sent.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing RunQueryResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing RunQueryResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const datastore = require('@google-cloud/datastore');

var client = new datastore.v1.DatastoreClient({
  // optional auth parameters.
});

var projectId = '';
var partitionId = {};
var request = {
  projectId: projectId,
  partitionId: partitionId,
};
client.runQuery(request)
  .then(responses => {
    var response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });