v1. DatastoreClient
Each RPC normalizes the partition IDs of the keys in its input entities, and always returns entities with keys with normalized partition IDs. This applies to all keys and entities, including those in values, except keys with both an empty path and an empty or unset partition ID. Normalization of input keys sets the project ID (if not already set) to the project ID from the request.
Constructor
DatastoreClient
new DatastoreClient(options)
Construct an instance of DatastoreClient.
Parameter |
|||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Optional object The configuration object. See the subsequent parameters for more details. Values in
|
Properties
port
The port for this API service.
scopes
The scopes needed to make gRPC calls for every method defined in this service.
servicePath
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. Values in
|
||||||
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');
const client = new datastore.v1.DatastoreClient({
// optional auth parameters.
});
const projectId = '';
const keys = [];
const request = {
projectId: projectId,
keys: keys,
};
client.allocateIds(request)
.then(responses => {
const 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. Values in
|
||||||
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');
const client = new datastore.v1.DatastoreClient({
// optional auth parameters.
});
const projectId = '';
client.beginTransaction({projectId: projectId})
.then(responses => {
const 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. Values in
|
||||||||||
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');
const client = new datastore.v1.DatastoreClient({
// optional auth parameters.
});
const projectId = '';
const mode = 'MODE_UNSPECIFIED';
const mutations = [];
const request = {
projectId: projectId,
mode: mode,
mutations: mutations,
};
client.commit(request)
.then(responses => {
const 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. Values in
|
||||||||
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');
const client = new datastore.v1.DatastoreClient({
// optional auth parameters.
});
const projectId = '';
const keys = [];
const request = {
projectId: projectId,
keys: keys,
};
client.lookup(request)
.then(responses => {
const 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. Values in
|
||||||||
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');
const client = new datastore.v1.DatastoreClient({
// optional auth parameters.
});
const projectId = '';
const keys = [];
const request = {
projectId: projectId,
keys: keys,
};
client.reserveIds(request)
.then(responses => {
const 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. Values in
|
||||||
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');
const client = new datastore.v1.DatastoreClient({
// optional auth parameters.
});
const projectId = '';
const transaction = '';
const request = {
projectId: projectId,
transaction: transaction,
};
client.rollback(request)
.then(responses => {
const 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. Values in
|
||||||||||||
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');
const client = new datastore.v1.DatastoreClient({
// optional auth parameters.
});
const projectId = '';
const partitionId = {};
const request = {
projectId: projectId,
partitionId: partitionId,
};
client.runQuery(request)
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});