DatastoreAdminClient

DatastoreAdminClient

Google Cloud Datastore Admin API

The Datastore Admin API provides several admin services for Cloud Datastore.


Concepts

Project, namespace, kind, and entity as defined in the Google Cloud Datastore API.

Operation: An Operation represents work being performed in the background.

EntityFilter: Allows specifying a subset of entities in a project. This is specified as a combination of kinds and namespaces (either or both of which may be all).


Services

Export/Import

The Export/Import service provides the ability to copy all or a subset of entities to/from Google Cloud Storage.

Exported data may be imported into Cloud Datastore for any Google Cloud Platform project. It is not restricted to the export source project. It is possible to export from one project and then import into another.

Exported data can also be loaded into Google BigQuery for analysis.

Exports and imports are performed asynchronously. An Operation resource is created for each export/import. The state (including any errors encountered) of the export/import may be queried via the Operation resource.

Index

The index service manages Cloud Datastore composite indexes.

Index creation and deletion are performed asynchronously. An Operation resource is created for each such asynchronous operation. The state of the operation (including any errors encountered) may be queried via the Operation resource.

Operation

The Operations collection provides a record of actions performed for the specified project (including any operations in progress). Operations are not created directly but through calls on other collections or resources.

An operation that is not yet done may be cancelled. The request to cancel is asynchronous and the operation may continue to run for some time after the request to cancel is made.

An operation that is done may be deleted so that it is no longer listed as part of the Operation collection.

ListOperations returns all pending operations, but not completed operations.

Operations are created by service DatastoreAdmin, but are accessed via service google.longrunning.Operations.

Constructor

new DatastoreAdminClient(optionsopt, fallback)

Construct an instance of DatastoreAdminClient.

Parameters:
Name Type Attributes Description
options object <optional>

The configuration object. The options accepted by the constructor are described in detail in this document. The common options are:

Properties
Name Type Attributes Description
credentials object <optional>

Credentials object.

Properties
Name Type Attributes Description
client_email string <optional>
private_key string <optional>
email string <optional>

Account email address. Required when using a .pem or .p12 keyFilename.

keyFilename string <optional>

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option below is not necessary. NOTE: .pem and .p12 require you to specify options.email as well.

port number <optional>

The port on which to connect to the remote host.

projectId string <optional>

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

apiEndpoint string <optional>

The domain name of the API remote host.

clientConfig gax.ClientConfig <optional>

client configuration override. TODO(@alexander-fenster): link to gax documentation.

fallback boolean

Use HTTP fallback mode. In fallback mode, a special browser-compatible transport implementation is used instead of gRPC transport. In browser context (if the window object is defined) the fallback mode is enabled automatically; set options.fallback to false if you need to override this behavior.

Members

apiEndpoint

The DNS address for this API service - same as servicePath(), exists for compatibility reasons.

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

(async) checkExportEntitiesProgress(name) → {Promise}

Check the status of the long running operation returned by exportEntities().

Parameters:
Name Type Description
name String

The operation name that will be passed.

Returns:
Type Description
Promise
  • The promise which resolves to an object. The decoded operation object has result and metadata field to get information from. Please see the documentation for more details and examples.
Example
const decodedOperation = await checkExportEntitiesProgress(name);
console.log(decodedOperation.result);
console.log(decodedOperation.done);
console.log(decodedOperation.metadata);

(async) checkImportEntitiesProgress(name) → {Promise}

Check the status of the long running operation returned by importEntities().

Parameters:
Name Type Description
name String

The operation name that will be passed.

Returns:
Type Description
Promise
  • The promise which resolves to an object. The decoded operation object has result and metadata field to get information from. Please see the documentation for more details and examples.
Example
const decodedOperation = await checkImportEntitiesProgress(name);
console.log(decodedOperation.result);
console.log(decodedOperation.done);
console.log(decodedOperation.metadata);

close() → {Promise}

Terminate the gRPC channel and close the client.

The client will no longer be usable and all future behavior is undefined.

Returns:
Type Description
Promise

A promise that resolves when the client is closed.

exportEntities(request, optionsopt) → {Promise}

Exports a copy of all or a subset of entities from Google Cloud Datastore to another storage system, such as Google Cloud Storage. Recent updates to entities may not be reflected in the export. The export occurs in the background and its progress can be monitored and managed via the Operation resource that is created. The output of an export may only be used once the associated operation is done. If an export operation is cancelled before completion it may leave partial data behind in Google Cloud Storage.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
projectId string

Required. Project ID against which to make the request.

labels Array.<number>

Client-assigned labels.

entityFilter google.datastore.admin.v1.EntityFilter

Description of what data from the project is included in the export.

outputUrlPrefix string

Required. Location for the export metadata and data files.

The full resource URL of the external storage location. Currently, only Google Cloud Storage is supported. So output_url_prefix should be of the form: gs://BUCKET_NAME[/NAMESPACE_PATH], where BUCKET_NAME is the name of the Cloud Storage bucket and NAMESPACE_PATH is an optional Cloud Storage namespace path (this is not a Cloud Datastore namespace). For more information about Cloud Storage namespace paths, see Object name considerations.

The resulting files will be nested deeper than the specified URL prefix. The final output URL will be provided in the google.datastore.admin.v1.ExportEntitiesResponse.output_url field. That value should be used for subsequent ImportEntities operations.

By nesting the data files deeper, the same Cloud Storage bucket can be used in multiple ExportEntities operations without conflict.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
  • The promise which resolves to an array. The first element of the array is an object representing a long running operation. Its promise() method returns a promise you can await for. Please see the documentation for more details and examples.
Example
const [operation] = await client.exportEntities(request);
const [response] = await operation.promise();

getIndex(request, optionsopt) → {Promise}

Gets an index.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
projectId string

Project ID against which to make the request.

indexId string

The resource ID of the index to get.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
  • The promise which resolves to an array. The first element of the array is an object representing Index. Please see the documentation for more details and examples.
Example
const [response] = await client.getIndex(request);

getProjectId() → {Promise}

Return the project ID used by this class.

Returns:
Type Description
Promise

A promise that resolves to string containing the project ID.

importEntities(request, optionsopt) → {Promise}

Imports entities into Google Cloud Datastore. Existing entities with the same key are overwritten. The import occurs in the background and its progress can be monitored and managed via the Operation resource that is created. If an ImportEntities operation is cancelled, it is possible that a subset of the data has already been imported to Cloud Datastore.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
projectId string

Required. Project ID against which to make the request.

labels Array.<number>

Client-assigned labels.

inputUrl string

Required. The full resource URL of the external storage location. Currently, only Google Cloud Storage is supported. So input_url should be of the form: gs://BUCKET_NAME[/NAMESPACE_PATH]/OVERALL_EXPORT_METADATA_FILE, where BUCKET_NAME is the name of the Cloud Storage bucket, NAMESPACE_PATH is an optional Cloud Storage namespace path (this is not a Cloud Datastore namespace), and OVERALL_EXPORT_METADATA_FILE is the metadata file written by the ExportEntities operation. For more information about Cloud Storage namespace paths, see Object name considerations.

For more information, see google.datastore.admin.v1.ExportEntitiesResponse.output_url.

entityFilter google.datastore.admin.v1.EntityFilter

Optionally specify which kinds/namespaces are to be imported. If provided, the list must be a subset of the EntityFilter used in creating the export, otherwise a FAILED_PRECONDITION error will be returned. If no filter is specified then all entities from the export are imported.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
  • The promise which resolves to an array. The first element of the array is an object representing a long running operation. Its promise() method returns a promise you can await for. Please see the documentation for more details and examples.
Example
const [operation] = await client.importEntities(request);
const [response] = await operation.promise();

initialize() → {Promise}

Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.

You can await on this method if you want to make sure the client is initialized.

Returns:
Type Description
Promise

A promise that resolves to an authenticated service stub.

listIndexes(request, optionsopt) → {Promise}

Lists the indexes that match the specified filters. Datastore uses an eventually consistent query to fetch the list of indexes and may occasionally return stale results.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
projectId string

Project ID against which to make the request.

filter string
pageSize number

The maximum number of items to return. If zero, then all results will be returned.

pageToken string

The next_page_token value returned from a previous List request, if any.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
  • The promise which resolves to an array. The first element of the array is Array of Index. The client library will perform auto-pagination by default: it will call the API as many times as needed and will merge results from all the pages into this array. Note that it can affect your quota. We recommend using listIndexesAsync() method described below for async iteration which you can stop as needed. Please see the documentation for more details and examples.

listIndexesAsync(request, optionsopt) → {Object}

Equivalent to listIndexes, but returns an iterable object.

for-await-of syntax is used with the iterable to get response elements on-demand.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
projectId string

Project ID against which to make the request.

filter string
pageSize number

The maximum number of items to return. If zero, then all results will be returned.

pageToken string

The next_page_token value returned from a previous List request, if any.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Object

An iterable Object that allows async iteration. When you iterate the returned iterable, each element will be an object representing Index. The API will be called under the hood as needed, once per the page, so you can stop the iteration when you don't need more results. Please see the documentation for more details and examples.

Example
const iterable = client.listIndexesAsync(request);
for await (const response of iterable) {
  // process response
}

listIndexesStream(request, optionsopt) → {Stream}

Equivalent to method.name.toCamelCase(), but returns a NodeJS Stream object.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
projectId string

Project ID against which to make the request.

filter string
pageSize number

The maximum number of items to return. If zero, then all results will be returned.

pageToken string

The next_page_token value returned from a previous List request, if any.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Stream

An object stream which emits an object representing Index on 'data' event. The client library will perform auto-pagination by default: it will call the API as many times as needed. Note that it can affect your quota. We recommend using listIndexesAsync() method described below for async iteration which you can stop as needed. Please see the documentation for more details and examples.