1 | /*!
|
2 | * Copyright 2018 Google LLC.
|
3 | *
|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | * you may not use this file except in compliance with the License.
|
6 | * You may obtain a copy of the License at
|
7 | *
|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
9 | *
|
10 | * Unless required by applicable law or agreed to in writing, software
|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 | * See the License for the specific language governing permissions and
|
14 | * limitations under the License.
|
15 | */
|
16 | import { ClientStub, ChannelCredentials, GoogleAuth, GoogleAuthOptions, CallOptions, Operation, ServiceError } from 'google-gax';
|
17 | import { entity, Entities, Entity, ValueProto } from './entity';
|
18 | import { AggregateField } from './aggregate';
|
19 | import Key = entity.Key;
|
20 | export { Entity, Key, AggregateField };
|
21 | import { PropertyFilter, and, or } from './filter';
|
22 | export { PropertyFilter, and, or };
|
23 | import { GetIndexesCallback, GetIndexesOptions, GetIndexesResponse, Index } from './index-class';
|
24 | import { Query } from './query';
|
25 | import { DatastoreRequest, CommitCallback, CommitResponse, SaveCallback, SaveResponse } from './request';
|
26 | import { Transaction } from './transaction';
|
27 | import { google } from '../protos/protos';
|
28 | import { AggregateQuery } from './aggregate';
|
29 | export type PathType = string | number | entity.Int;
|
30 | export interface BooleanObject {
|
31 | [key: string]: boolean;
|
32 | }
|
33 | export interface EntityProtoReduceAccumulator {
|
34 | [key: string]: ValueProto;
|
35 | }
|
36 | export interface EntityProtoReduceData {
|
37 | value: ValueProto;
|
38 | excludeFromIndexes: ValueProto;
|
39 | name: string | number;
|
40 | }
|
41 | export type UpdateCallback = CommitCallback;
|
42 | export type UpdateResponse = CommitResponse;
|
43 | export type UpsertCallback = CommitCallback;
|
44 | export type UpsertResponse = CommitResponse;
|
45 | export type InsertCallback = CommitCallback;
|
46 | export type InsertResponse = CommitResponse;
|
47 | export interface LongRunningCallback {
|
48 | (err: ServiceError | null, operation?: Operation, apiResponse?: google.longrunning.IOperation): void;
|
49 | }
|
50 | export type LongRunningResponse = [Operation, google.longrunning.IOperation];
|
51 | export type Fallback = boolean | 'rest' | 'proto';
|
52 | export interface ExportEntitiesConfig extends Omit<google.datastore.admin.v1.IExportEntitiesRequest, 'projectId'> {
|
53 | bucket?: string | {
|
54 | name: string;
|
55 | };
|
56 | kinds?: string[];
|
57 | namespaces?: string[];
|
58 | gaxOptions?: CallOptions;
|
59 | }
|
60 | export interface ImportEntitiesConfig extends Omit<google.datastore.admin.v1.IImportEntitiesRequest, 'projectId'> {
|
61 | file?: string | {
|
62 | bucket: {
|
63 | name: string;
|
64 | };
|
65 | name: string;
|
66 | };
|
67 | kinds?: string[];
|
68 | namespaces?: string[];
|
69 | gaxOptions?: CallOptions;
|
70 | }
|
71 | /**
|
72 | * Idiomatic class for interacting with Cloud Datastore. Uses the lower-level
|
73 | * {@link DatastoreClient} class under the hood.
|
74 | *
|
75 | * In addition to the constructor options shown here, the {@link Datastore}
|
76 | * class constructor accepts the same options accepted by
|
77 | * {@link DatastoreClient}.
|
78 | *
|
79 | * <h4>The Datastore Emulator</h4>
|
80 | *
|
81 | * Make sure you have the <a href="https://cloud.google.com/sdk/downloads">
|
82 | * gcloud SDK installed</a>, then run:
|
83 | *
|
84 | * <pre>
|
85 | * $ gcloud beta emulators datastore start --no-legacy
|
86 | * </pre>
|
87 | *
|
88 | * You will see the following printed:
|
89 | *
|
90 | * <pre>
|
91 | * [datastore] API endpoint: http://localhost:8005
|
92 | * [datastore] If you are using a library that supports the
|
93 | * DATASTORE_EMULATOR_HOST environment variable, run:
|
94 | * [datastore]
|
95 | * [datastore] export DATASTORE_EMULATOR_HOST=localhost:8005
|
96 | * [datastore]
|
97 | * [datastore] Dev App Server is now running.
|
98 | * </pre>
|
99 | *
|
100 | * Set that environment variable and your localhost Datastore will
|
101 | * automatically be used. You can also pass this address in manually with
|
102 | * `apiEndpoint`.
|
103 | *
|
104 | * Additionally, `DATASTORE_PROJECT_ID` is recognized. If you have this set,
|
105 | * you don't need to provide a `projectId`.
|
106 | *
|
107 | *
|
108 | * See {@link https://cloud.google.com/datastore/docs/concepts/overview| Cloud Datastore Concepts Overview}
|
109 | *
|
110 | * @param {object} [options] Configuration options.
|
111 | * @param {string} [options.apiEndpoint] Override the default API endpoint used
|
112 | * to reach Datastore. This is useful for connecting to your local Datastore
|
113 | * server (usually "http://localhost:8080").
|
114 | * @param {string} [options.namespace] Namespace to isolate transactions to.
|
115 | *
|
116 | * @example Import the client library
|
117 | * ```
|
118 | * const {Datastore} = require('@google-cloud/datastore');
|
119 | *
|
120 | * ```
|
121 | * @example Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:
|
122 | * ```
|
123 | * const datastore = new Datastore();
|
124 | *
|
125 | * ```
|
126 | * @example Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>:
|
127 | * ```
|
128 | * const datastore = new Datastore({
|
129 | * projectId: 'your-project-id',
|
130 | * keyFilename: '/path/to/keyfile.json'
|
131 | * });
|
132 | *
|
133 | * ```
|
134 | * @example Retrieving Records
|
135 | * ```
|
136 | * const {Datastore} = require('@google-cloud/datastore');
|
137 | * const datastore = new Datastore();
|
138 | *
|
139 | * // Records, called "entities" in Datastore, are retrieved by using a key. The
|
140 | * // key is more than a numeric identifier, it is a complex data structure that
|
141 | * // can be used to model relationships. The simplest key has a string `kind`
|
142 | * // value, and either a numeric `id` value, or a string `name` value.
|
143 | * //
|
144 | * // A single record can be retrieved with {@link Datastore#key} and
|
145 | * // {@link Datastore#get}.
|
146 | * //-
|
147 | * const key = datastore.key(['Company', 'Google']);
|
148 | *
|
149 | * datastore.get(key, function(err, entity) {
|
150 | * // entity = The record.
|
151 | * // entity[datastore.KEY] = The key for this entity.
|
152 | * });
|
153 | *
|
154 | * //-
|
155 | * // <h3>Querying Records</h3>
|
156 | * //
|
157 | * // Create a query with {@link Datastore#createQuery}.
|
158 | * //-
|
159 | * const query = datastore.createQuery('Company');
|
160 | *
|
161 | * //-
|
162 | * // Multiple records can be found that match criteria with
|
163 | * // {@link Query#filter}.
|
164 | * //-
|
165 | * query.filter('location', 'CA');
|
166 | *
|
167 | * //-
|
168 | * // Records can also be ordered with {@link Query#order}.
|
169 | * //-
|
170 | * query.order('name');
|
171 | *
|
172 | * //-
|
173 | * // The number of records returned can be specified with
|
174 | * // {@link Query#limit}.
|
175 | * //-
|
176 | * query.limit(5);
|
177 | *
|
178 | * //-
|
179 | * // Records' key structures can also be queried with
|
180 | * // {@link Query#hasAncestor}.
|
181 | * //-
|
182 | * const ancestorKey = datastore.key(['ParentCompany', 'Alphabet']);
|
183 | *
|
184 | * query.hasAncestor(ancestorKey);
|
185 | *
|
186 | * //-
|
187 | * // Run the query with {@link Datastore#runQuery}.
|
188 | * //-
|
189 | * datastore.runQuery(query, (err, entities) => {
|
190 | * // entities = An array of records.
|
191 | *
|
192 | * // Access the Key object for an entity.
|
193 | * const firstEntityKey = entities[0][datastore.KEY];
|
194 | * });
|
195 | *
|
196 | * ```
|
197 | * @example Paginating Records
|
198 | * ```
|
199 | * // Imagine building a website that allows a user to sift through hundreds of
|
200 | * // their contacts. You'll likely want to only display a subset of these at
|
201 | * // once, so you set a limit.
|
202 | * //-
|
203 | * const express = require('express');
|
204 | * const app = express();
|
205 | *
|
206 | * const NUM_RESULTS_PER_PAGE = 15;
|
207 | *
|
208 | * app.get('/contacts', (req, res) => {
|
209 | * const query = datastore.createQuery('Contacts')
|
210 | * .limit(NUM_RESULTS_PER_PAGE);
|
211 | *
|
212 | * if (req.query.nextPageCursor) {
|
213 | * query.start(req.query.nextPageCursor);
|
214 | * }
|
215 | *
|
216 | * datastore.runQuery(query, (err, entities, info) => {
|
217 | * if (err) {
|
218 | * // Error handling omitted.
|
219 | * return;
|
220 | * }
|
221 | *
|
222 | * // Respond to the front end with the contacts and the cursoring token
|
223 | * // from the query we just ran.
|
224 | * const frontEndResponse = {
|
225 | * contacts: entities
|
226 | * };
|
227 | *
|
228 | * // Check if more results may exist.
|
229 | * if (info.moreResults !== datastore.NO_MORE_RESULTS) {
|
230 | * frontEndResponse.nextPageCursor = info.endCursor;
|
231 | * }
|
232 | *
|
233 | * res.render('contacts', frontEndResponse);
|
234 | * });
|
235 | * });
|
236 | *
|
237 | * ```
|
238 | * @example Creating Records
|
239 | * ```
|
240 | * // New entities can be created and persisted with {@link Datastore#save}.
|
241 | * // The entity must have a key to be saved. If you don't specify an
|
242 | * // identifier for the key, one is generated for you.
|
243 | * //
|
244 | * // We will create a key with a `name` identifier, "Google".
|
245 | * //-
|
246 | * const key = datastore.key(['Company', 'Google']);
|
247 | *
|
248 | * const data = {
|
249 | * name: 'Google',
|
250 | * location: 'CA'
|
251 | * };
|
252 | *
|
253 | * datastore.save({
|
254 | * key: key,
|
255 | * data: data
|
256 | * }, (err) => {
|
257 | * if (!err) {
|
258 | * // Record saved successfully.
|
259 | * }
|
260 | * });
|
261 | *
|
262 | * //-
|
263 | * // We can verify the data was saved by using {@link Datastore#get}.
|
264 | * //-
|
265 | * datastore.get(key, (err, entity) => {
|
266 | * // entity = {
|
267 | * // name: 'Google',
|
268 | * // location: 'CA'
|
269 | * // }
|
270 | * });
|
271 | *
|
272 | * //-
|
273 | * // If we want to update this record, we can modify the data object and re-
|
274 | * // save it.
|
275 | * //-
|
276 | * data.symbol = 'GOOG';
|
277 | *
|
278 | * datastore.save({
|
279 | * key: key, // defined above (datastore.key(['Company', 'Google']))
|
280 | * data: data
|
281 | * }, (err, entity) => {
|
282 | * if (!err) {
|
283 | * // Record updated successfully.
|
284 | * }
|
285 | * });
|
286 | *
|
287 | * ```
|
288 | * @example Deleting Records
|
289 | * ```
|
290 | * // Entities can be removed from Datastore by passing the entity's key object
|
291 | * // to {@link Datastore#delete}.
|
292 | * //-
|
293 | * const key = datastore.key(['Company', 'Google']);
|
294 | *
|
295 | * datastore.delete(key, (err) => {
|
296 | * if (!err) {
|
297 | * // Record deleted successfully.
|
298 | * }
|
299 | * });
|
300 | *
|
301 | * ```
|
302 | * @example Transactions
|
303 | * ```
|
304 | * // Complex logic can be wrapped in a transaction with
|
305 | * // {@link Datastore#transaction}. All queries and updates run within
|
306 | * // the transaction will be applied when the `done` function is called.
|
307 | * //-
|
308 | * const transaction = datastore.transaction();
|
309 | *
|
310 | * transaction.run((err) => {
|
311 | * if (err) {
|
312 | * // Error handling omitted.
|
313 | * }
|
314 | *
|
315 | * const key = datastore.key(['Company', 'Google']);
|
316 | *
|
317 | * transaction.get(key, (err, entity) => {
|
318 | * if (err) {
|
319 | * // Error handling omitted.
|
320 | * }
|
321 | *
|
322 | * entity.symbol = 'GOOG';
|
323 | *
|
324 | * transaction.save(entity);
|
325 | *
|
326 | * transaction.commit((err) => {
|
327 | * if (!err) {
|
328 | * // Transaction committed successfully.
|
329 | * }
|
330 | * });
|
331 | * });
|
332 | * });
|
333 | *
|
334 | * ```
|
335 | * @example Queries with Ancestors
|
336 | * ```
|
337 | * const {Datastore} = require('@google-cloud/datastore');
|
338 | * const datastore = new Datastore();
|
339 | *
|
340 | * const customerId1 = 2993844;
|
341 | * const customerId2 = 4993882;
|
342 | * const customerKey1 = datastore.key(['Customer', customerId1]);
|
343 | * const customerKey2 = datastore.key(['Customer', customerId2]);
|
344 | * const cookieKey1 = datastore.key(['Customer', customerId1, 'Cookie',
|
345 | * 'cookie28839']); // child entity const cookieKey2 =
|
346 | * datastore.key(['Customer', customerId1, 'Cookie', 'cookie78984']); // child
|
347 | * entity const cookieKey3 = datastore.key(['Customer', customerId2, 'Cookie',
|
348 | * 'cookie93911']); // child entity
|
349 | *
|
350 | * const entities = [];
|
351 | *
|
352 | * entities.push({
|
353 | * key: customerKey1,
|
354 | * data: {
|
355 | * name: 'Jane Doe',
|
356 | * address: '4848 Liller'
|
357 | * }
|
358 | * });
|
359 | *
|
360 | * entities.push({
|
361 | * key: customerKey2,
|
362 | * data: {
|
363 | * name: 'John Smith',
|
364 | * address: '4848 Pine'
|
365 | * }
|
366 | * });
|
367 | *
|
368 | * entities.push({
|
369 | * key: cookieKey1,
|
370 | * data: {
|
371 | * cookieVal: 'dj83kks88rkld'
|
372 | * }
|
373 | * });
|
374 | *
|
375 | * entities.push({
|
376 | * key: cookieKey2,
|
377 | * data: {
|
378 | * cookieVal: 'sj843ka99s'
|
379 | * }
|
380 | * });
|
381 | *
|
382 | * entities.push({
|
383 | * key: cookieKey3,
|
384 | * data: {
|
385 | * cookieVal: 'otk82k2kw'
|
386 | * }
|
387 | * });
|
388 | *
|
389 | * datastore.upsert(entities);
|
390 | *
|
391 | * const query = datastore.createQuery().hasAncestor(customerKey1);
|
392 | *
|
393 | * datastore.runQuery(query, (err, entities) => {
|
394 | * for (let entity of entities) {
|
395 | * console.log(entity[datastore.KEY]);
|
396 | * }
|
397 | * });
|
398 | *
|
399 | * const query2 = datastore.createQuery().hasAncestor(customerKey2);
|
400 | *
|
401 | * datastore.runQuery(query2, (err, entities) => {
|
402 | * for (let entity of entities) {
|
403 | * console.log(entity[datastore.KEY]);
|
404 | * }
|
405 | * });
|
406 | *
|
407 | * datastore.runQuery(query2, (entities) => {
|
408 | * console.log(entities);
|
409 | * });
|
410 | * ```
|
411 | */
|
412 | declare class Datastore extends DatastoreRequest {
|
413 | clients_: Map<string, ClientStub>;
|
414 | namespace?: string;
|
415 | defaultBaseUrl_: string;
|
416 | options: DatastoreOptions;
|
417 | baseUrl_?: string;
|
418 | port_?: number;
|
419 | customEndpoint_?: boolean;
|
420 | auth: GoogleAuth;
|
421 | constructor(options?: DatastoreOptions);
|
422 | /**
|
423 | * Create an aggregation query from a Query.
|
424 | *
|
425 | * @param {Query} query A Query object.
|
426 | */
|
427 | createAggregationQuery(query: Query): AggregateQuery;
|
428 | /**
|
429 | * Export entities from this project to a Google Cloud Storage bucket.
|
430 | *
|
431 | * @param {ExportEntitiesConfig} config Configuration object.
|
432 | * @param {string | Bucket} config.bucket The `gs://bucket` path or a
|
433 | * @google-cloud/storage Bucket object.
|
434 | * @param {string[]} [config.kinds] The kinds to include in this import.
|
435 | * @param {string[]} [config.namespaces] The namespace IDs to include in this
|
436 | * import.
|
437 | * @param {object} [config.gaxOptions] Request configuration options, outlined
|
438 | * here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
439 | * @param {function} callback The callback function.
|
440 | * @param {?error} callback.err An error returned while making this request.
|
441 | * @param {Operation} callback.operation An operation object that can be used
|
442 | * to check the status of the request.
|
443 | */
|
444 | export(config: ExportEntitiesConfig): Promise<LongRunningResponse>;
|
445 | export(config: ExportEntitiesConfig, callback: LongRunningCallback): void;
|
446 | /**
|
447 | * Get all of the indexes in this project.
|
448 | *
|
449 | * @param {GetIndexesOptions | GetIndexesCallback} [optionsOrCallback]
|
450 | * @param {object} [options.gaxOptions] Request configuration options,
|
451 | * outlined here:
|
452 | * https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
453 | * @param {GetIndexesResponse} [callback] The callback function.
|
454 | * @param {?error} callback.error An error returned while making this request.
|
455 | * @param {Index[]} callback.indexes All matching Index instances.
|
456 | * @param {object} callback.apiResponse The full API response.
|
457 | * @return {void | Promise<GetIndexesResponse>}
|
458 | */
|
459 | getIndexes(options?: GetIndexesOptions): Promise<GetIndexesResponse>;
|
460 | getIndexes(options: GetIndexesOptions, callback: GetIndexesCallback): void;
|
461 | getIndexes(callback: GetIndexesCallback): void;
|
462 | /**
|
463 | * Get all of the indexes in this project as a readable object stream.
|
464 | *
|
465 | * @param {GetIndexesOptions} [options] Configuration object. See
|
466 | * {@link Datastore#getIndexes} for a complete list of options.
|
467 | * @returns {ReadableStream<Index>}
|
468 | */
|
469 | getIndexesStream(options?: GetIndexesOptions): NodeJS.ReadableStream;
|
470 | /**
|
471 | * Gets the database id that all requests will be run against.
|
472 | *
|
473 | * @returns {string} The database id that the current client is set to that
|
474 | * requests will run against.
|
475 | */
|
476 | getDatabaseId(): string | undefined;
|
477 | getProjectId(): Promise<string>;
|
478 | /**
|
479 | * Import entities into this project from a remote file.
|
480 | *
|
481 | * @param {ImportEntitiesConfig} config Configuration object.
|
482 | * @param {string | File} config.file The `gs://bucket/file` path or a
|
483 | * @google-cloud/storage File object.
|
484 | * @param {string[]} [config.kinds] The kinds to include in this import.
|
485 | * @param {string[]} [config.namespaces] The namespace IDs to include in this
|
486 | * import.
|
487 | * @param {object} [config.gaxOptions] Request configuration options, outlined
|
488 | * here: https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
489 | * @param {function} callback The callback function.
|
490 | * @param {?error} callback.err An error returned while making this request.
|
491 | * @param {Operation} callback.operation An operation object that can be used
|
492 | * to check the status of the request.
|
493 | */
|
494 | import(config: ImportEntitiesConfig): Promise<LongRunningResponse>;
|
495 | import(config: ImportEntitiesConfig, callback: LongRunningCallback): void;
|
496 | /**
|
497 | * Get a reference to an Index.
|
498 | *
|
499 | * @param {string} id The index name or id.
|
500 | * @returns {Index}
|
501 | */
|
502 | index(id: string): Index;
|
503 | /**
|
504 | * Maps to {@link https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore#_google_cloud_datastore_Datastore_save_member_1_|Datastore#save}, forcing the method to be `insert`.
|
505 | *
|
506 | * @param {object|object[]} entities Datastore key object(s).
|
507 | * @param {Key} entities.key Datastore key object.
|
508 | * @param {string[]} [entities.excludeFromIndexes] Exclude properties from
|
509 | * indexing using a simple JSON path notation. See the examples in
|
510 | * {@link Datastore#save} to see how to target properties at different
|
511 | * levels of nesting within your entity.
|
512 | * @param {object} entities.data Data to save with the provided key.
|
513 | * @param {function} callback The callback function.
|
514 | * @param {?error} callback.err An error returned while making this request
|
515 | * @param {object} callback.apiResponse The full API response.
|
516 | */
|
517 | insert(entities: Entities): Promise<InsertResponse>;
|
518 | insert(entities: Entities, callback: InsertCallback): void;
|
519 | /**
|
520 | * Insert or update the specified object(s). If a key is incomplete, its
|
521 | * associated object is inserted and the original Key object is updated to
|
522 | * contain the generated ID.
|
523 | *
|
524 | * This method will determine the correct Datastore method to execute
|
525 | * (`upsert`, `insert`, or `update`) by using the key(s) provided. For
|
526 | * example, if you provide an incomplete key (one without an ID), the request
|
527 | * will create a new entity and have its ID automatically assigned. If you
|
528 | * provide a complete key, the entity will be updated with the data specified.
|
529 | *
|
530 | * By default, all properties are indexed. To prevent a property from being
|
531 | * included in *all* indexes, you must supply an `excludeFromIndexes` array.
|
532 | *
|
533 | * To prevent large properties from being included in *all* indexes, you must supply
|
534 | * `excludeLargeProperties: true`.
|
535 | * See below for an example.
|
536 | *
|
537 | * @borrows {@link Transaction#save} as save
|
538 | *
|
539 | * @throws {Error} If an unrecognized method is provided.
|
540 | *
|
541 | * @param {object|object[]} entities Datastore key object(s).
|
542 | * @param {Key} entities.key Datastore key object.
|
543 | * @param {string[]} [entities.excludeFromIndexes] Exclude properties from
|
544 | * indexing using a simple JSON path notation. See the example below to
|
545 | * see how to target properties at different levels of nesting within your
|
546 | * @param {boolean} [entities.excludeLargeProperties] Automatically exclude
|
547 | * large properties from indexing. It help in storing large values.
|
548 | * @param {string} [entities.method] Explicit method to use, either 'insert',
|
549 | * 'update', or 'upsert'.
|
550 | * @param {object} entities.data Data to save with the provided key.
|
551 | * entity.
|
552 | * @param {object} [gaxOptions] Request configuration options, outlined here:
|
553 | * https://googleapis.github.io/gax-nodejs/global.html#CallOptions.
|
554 | * @param {function} callback The callback function.
|
555 | * @param {?error} callback.err An error returned while making this request
|
556 | * @param {object} callback.apiResponse The full API response.
|
557 | *
|
558 | * @example
|
559 | * ```
|
560 | * //-
|
561 | * // Save a single entity.
|
562 | * //
|
563 | * // Notice that we are providing an incomplete key. After saving, the
|
564 | * // original Key object used to save will be updated to contain the path
|
565 | * // with its generated ID.
|
566 | * //-
|
567 | * const key = datastore.key('Company');
|
568 | * const entity = {
|
569 | * key: key,
|
570 | * data: {
|
571 | * rating: '10'
|
572 | * }
|
573 | * };
|
574 | *
|
575 | * datastore.save(entity, (err) => {
|
576 | * console.log(key.path); // [ 'Company', 5669468231434240 ]
|
577 | * console.log(key.namespace); // undefined
|
578 | * });
|
579 | *
|
580 | * //-
|
581 | * // Save a single entity using a provided name instead of auto-generated ID.
|
582 | * //
|
583 | * // Here we are providing a key with name instead of an ID. After saving,
|
584 | * // the original Key object used to save will be updated to contain the
|
585 | * // path with the name instead of a generated ID.
|
586 | * //-
|
587 | * const key = datastore.key(['Company', 'donutshack']);
|
588 | * const entity = {
|
589 | * key: key,
|
590 | * data: {
|
591 | * name: 'DonutShack',
|
592 | * rating: 8
|
593 | * }
|
594 | * };
|
595 | *
|
596 | * datastore.save(entity, (err) => {
|
597 | * console.log(key.path); // ['Company', 'donutshack']
|
598 | * console.log(key.namespace); // undefined
|
599 | * });
|
600 | *
|
601 | * //-
|
602 | * // Save a single entity with a provided namespace. Namespaces allow for
|
603 | * // multitenancy. To read more about this, see
|
604 | * // [the Datastore docs on key concepts](https://goo.gl/M1LUAu).
|
605 | * //
|
606 | * // Here we are providing a key with namespace.
|
607 | * //-
|
608 | * const key = datastore.key({
|
609 | * namespace: 'my-namespace',
|
610 | * path: ['Company', 'donutshack']
|
611 | * });
|
612 | *
|
613 | * const entity = {
|
614 | * key: key,
|
615 | * data: {
|
616 | * name: 'DonutShack',
|
617 | * rating: 8
|
618 | * }
|
619 | * };
|
620 | *
|
621 | * datastore.save(entity, (err) => {
|
622 | * console.log(key.path); // ['Company', 'donutshack']
|
623 | * console.log(key.namespace); // 'my-namespace'
|
624 | * });
|
625 | *
|
626 | * //-
|
627 | * // Save different types of data, including ints, doubles, dates, booleans,
|
628 | * // blobs, and lists.
|
629 | * //
|
630 | * // Notice that we are providing an incomplete key. After saving, the
|
631 | * // original Key object used to save will be updated to contain the path
|
632 | * // with its generated ID.
|
633 | * //-
|
634 | * const key = datastore.key('Company');
|
635 | * const entity = {
|
636 | * key: key,
|
637 | * data: {
|
638 | * name: 'DonutShack',
|
639 | * rating: datastore.int(10),
|
640 | * worth: datastore.double(123456.78),
|
641 | * location: datastore.geoPoint({
|
642 | * latitude: 40.6894,
|
643 | * longitude: -74.0447
|
644 | * }),
|
645 | * numDonutsServed: 45,
|
646 | * founded: new Date('Tue May 12 2015 15:30:00 GMT-0400 (EDT)'),
|
647 | * isStartup: true,
|
648 | * donutEmoji: Buffer.from('\uD83C\uDF69'),
|
649 | * keywords: [
|
650 | * 'donut',
|
651 | * 'coffee',
|
652 | * 'yum'
|
653 | * ]
|
654 | * }
|
655 | * };
|
656 | *
|
657 | * datastore.save(entity, (err, apiResponse) => {});
|
658 | *
|
659 | * //-
|
660 | * // Use an array, `excludeFromIndexes`, to exclude properties from indexing.
|
661 | * // This will allow storing string values larger than 1500 bytes.
|
662 | * //-
|
663 | * const entity = {
|
664 | * key: datastore.key('Company'),
|
665 | * excludeFromIndexes: [
|
666 | * 'description',
|
667 | * 'embeddedEntity.description',
|
668 | * 'arrayValue[]',
|
669 | * 'arrayValue[].description'
|
670 | * ],
|
671 | * data: {
|
672 | * description: 'Long string (...)',
|
673 | * embeddedEntity: {
|
674 | * description: 'Long string (...)'
|
675 | * },
|
676 | * arrayValue: [
|
677 | * 'Long string (...)',
|
678 | * {
|
679 | * description: 'Long string (...)'
|
680 | * }
|
681 | * ]
|
682 | * }
|
683 | * };
|
684 | *
|
685 | * datastore.save(entity, (err, apiResponse) => {});
|
686 | *
|
687 | * //-
|
688 | * // Use boolean `excludeLargeProperties`, to auto exclude Large properties from indexing.
|
689 | * // This will allow storing string values larger than 1500 bytes.
|
690 | * //-
|
691 | * const entity = {
|
692 | * key: datastore.key('Company'),
|
693 | * data: {
|
694 | * description: 'Long string (...)',
|
695 | * embeddedEntity: {
|
696 | * description: 'Long string (...)'
|
697 | * },
|
698 | * arrayValue: [
|
699 | * 'Long string (...)',
|
700 | * {
|
701 | * description: 'Long string (...)'
|
702 | * }
|
703 | * ]
|
704 | * },
|
705 | * excludeLargeProperties: true
|
706 | * };
|
707 | *
|
708 | * datastore.save(entity, (err, apiResponse) => {});
|
709 | *
|
710 | * //-
|
711 | * // Save multiple entities at once.
|
712 | * //-
|
713 | * const companyKey = datastore.key(['Company', 123]);
|
714 | * const productKey = datastore.key(['Product', 'Computer']);
|
715 | * const entities = [
|
716 | * {
|
717 | * key: companyKey,
|
718 | * data: {
|
719 | * HQ: 'Dallas, TX'
|
720 | * }
|
721 | * },
|
722 | * {
|
723 | * key: productKey,
|
724 | * data: {
|
725 | * vendor: 'Dell'
|
726 | * }
|
727 | * }
|
728 | * ];
|
729 | *
|
730 | * datastore.save(entities, (err, apiResponse) => {});
|
731 | *
|
732 | * //-
|
733 | * // Explicitly attempt to 'insert' a specific entity.
|
734 | * //-
|
735 | * const userKey = datastore.key(['User', 'chilts']);
|
736 | * const entity = {
|
737 | * key: userKey,
|
738 | * method: 'insert',
|
739 | * data: {
|
740 | * fullName: 'Andrew Chilton'
|
741 | * }
|
742 | * };
|
743 | *
|
744 | * datastore.save(entity, (err, apiResponse) => {});
|
745 | *
|
746 | * //-
|
747 | * // Returns a Promise if callback is omitted.
|
748 | * //-
|
749 | * datastore.save(entity).then((data) => {
|
750 | * const apiResponse = data[0];
|
751 | * });
|
752 | * ```
|
753 | */
|
754 | save(entities: Entities, gaxOptions?: CallOptions): Promise<SaveResponse>;
|
755 | save(entities: Entities, gaxOptions: CallOptions, callback: SaveCallback): void;
|
756 | save(entities: Entities, callback: SaveCallback): void;
|
757 | /**
|
758 | * Maps to {@link https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore#_google_cloud_datastore_Datastore_save_member_1_|Datastore#save}, forcing the method to be `update`.
|
759 | *
|
760 | * @param {object|object[]} entities Datastore key object(s).
|
761 | * @param {Key} entities.key Datastore key object.
|
762 | * @param {string[]} [entities.excludeFromIndexes] Exclude properties from
|
763 | * indexing using a simple JSON path notation. See the examples in
|
764 | * {@link Datastore#save} to see how to target properties at different
|
765 | * levels of nesting within your entity.
|
766 | * @param {object} entities.data Data to save with the provided key.
|
767 | * @param {function} callback The callback function.
|
768 | * @param {?error} callback.err An error returned while making this request
|
769 | * @param {object} callback.apiResponse The full API response.
|
770 | */
|
771 | update(entities: Entities): Promise<UpdateResponse>;
|
772 | update(entities: Entities, callback: UpdateCallback): void;
|
773 | /**
|
774 | * Maps to {@link https://cloud.google.com/nodejs/docs/reference/datastore/latest/datastore/datastore#_google_cloud_datastore_Datastore_save_member_1_|Datastore#save}, forcing the method to be `upsert`.
|
775 | *
|
776 | * @param {object|object[]} entities Datastore key object(s).
|
777 | * @param {Key} entities.key Datastore key object.
|
778 | * @param {string[]} [entities.excludeFromIndexes] Exclude properties from
|
779 | * indexing using a simple JSON path notation. See the examples in
|
780 | * {@link Datastore#save} to see how to target properties at different
|
781 | * levels of nesting within your entity.
|
782 | * @param {object} entities.data Data to save with the provided key.
|
783 | * @param {function} callback The callback function.
|
784 | * @param {?error} callback.err An error returned while making this request
|
785 | * @param {object} callback.apiResponse The full API response.
|
786 | */
|
787 | upsert(entities: Entities): Promise<UpsertResponse>;
|
788 | upsert(entities: Entities, callback: UpsertCallback): void;
|
789 | /**
|
790 | * Helper function to get a Datastore Double object.
|
791 | *
|
792 | * @param {number} value The double value.
|
793 | * @returns {object}
|
794 | *
|
795 | * @example
|
796 | * ```
|
797 | * const {Datastore} = require('@google-cloud/datastore');
|
798 | * const datastore = new Datastore();
|
799 | * const threeDouble = datastore.double(3.0);
|
800 | * ```
|
801 | */
|
802 | static double(value: number): entity.Double;
|
803 | double(value: number): entity.Double;
|
804 | /**
|
805 | * Helper function to check if something is a Datastore Double object.
|
806 | *
|
807 | * @param {*} value
|
808 | * @returns {boolean}
|
809 | *
|
810 | * @example
|
811 | * ```
|
812 | * const {Datastore} = require('@google-cloud/datastore');
|
813 | * const datastore = new Datastore();
|
814 | * datastore.isDouble(0.42); // false
|
815 | * datastore.isDouble(datastore.double(0.42)); // true
|
816 | * ```
|
817 | */
|
818 | static isDouble(value?: {}): value is entity.Double;
|
819 | isDouble(value?: {}): value is entity.Double;
|
820 | /**
|
821 | * Helper function to get a Datastore Geo Point object.
|
822 | *
|
823 | * @param {object} coordinates Coordinate value.
|
824 | * @param {number} coordinates.latitude Latitudinal value.
|
825 | * @param {number} coordinates.longitude Longitudinal value.
|
826 | * @returns {object}
|
827 | *
|
828 | * @example
|
829 | * ```
|
830 | * const {Datastore} = require('@google-cloud/datastore');
|
831 | * const datastore = new Datastore();
|
832 | * const coordinates = {
|
833 | * latitude: 40.6894,
|
834 | * longitude: -74.0447
|
835 | * };
|
836 | *
|
837 | * const geoPoint = datastore.geoPoint(coordinates);
|
838 | *
|
839 | * //-
|
840 | * // List all companies that are located at 40.123 latitude
|
841 | * // and -74.0447 longitude.
|
842 | * //-
|
843 | * const query = datastore.createQuery('Company');
|
844 | * const companyQuery = query
|
845 | * .filter('geoPoint.latitude', datastore.double(40.123))
|
846 | * .filter('geoPoint.longitude', datastore.double(-74.0447));
|
847 | * ```
|
848 | */
|
849 | static geoPoint(coordinates: entity.Coordinates): entity.GeoPoint;
|
850 | geoPoint(coordinates: entity.Coordinates): entity.GeoPoint;
|
851 | /**
|
852 | * Helper function to check if something is a Datastore Geo Point object.
|
853 | *
|
854 | * @param {*} value
|
855 | * @returns {boolean}
|
856 | *
|
857 | * @example
|
858 | * ```
|
859 | * const {Datastore} = require('@google-cloud/datastore');
|
860 | * const datastore = new Datastore();
|
861 | * const coordinates = {
|
862 | * latitude: 0,
|
863 | * longitude: 0
|
864 | * };
|
865 | *
|
866 | * datastore.isGeoPoint(coordinates); // false
|
867 | * datastore.isGeoPoint(datastore.geoPoint(coordinates)); // true
|
868 | * ```
|
869 | */
|
870 | static isGeoPoint(value?: {}): value is entity.GeoPoint;
|
871 | isGeoPoint(value?: {}): value is entity.GeoPoint;
|
872 | /**
|
873 | * Helper function to get a Datastore Integer object.
|
874 | *
|
875 | * This is also useful when using an ID outside the bounds of a JavaScript
|
876 | * Number object.
|
877 | *
|
878 | * @param {number} value The integer value.
|
879 | * @returns {object}
|
880 | *
|
881 | * @example
|
882 | * ```
|
883 | * const {Datastore} = require('@google-cloud/datastore');
|
884 | * const datastore = new Datastore();
|
885 | * const sevenInteger = datastore.int(7);
|
886 | *
|
887 | * //-
|
888 | * // Create an Int to support long Key IDs.
|
889 | * //-
|
890 | * const key = datastore.key([
|
891 | * 'Kind',
|
892 | * datastore.int('100000000000001234')
|
893 | * ]);
|
894 | * ```
|
895 | */
|
896 | static int(value: number | string): entity.Int;
|
897 | int(value: number | string): entity.Int;
|
898 | /**
|
899 | * Helper function to check if something is a Datastore Integer object.
|
900 | *
|
901 | * @param {*} value
|
902 | * @returns {boolean}
|
903 | *
|
904 | * @example
|
905 | * ```
|
906 | * const {Datastore} = require('@google-cloud/datastore');
|
907 | * const datastore = new Datastore();
|
908 | * datastore.isInt(42); // false
|
909 | * datastore.isInt(datastore.int(42)); // true
|
910 | * ```
|
911 | */
|
912 | static isInt(value?: {}): value is entity.Int;
|
913 | isInt(value?: {}): value is entity.Int;
|
914 | /**
|
915 | * Access the Key from an Entity object.
|
916 | *
|
917 | * @name Datastore.KEY
|
918 | * @type {symbol}
|
919 | */
|
920 | /**
|
921 | * Access the Key from an Entity object.
|
922 | *
|
923 | * @name Datastore#KEY
|
924 | * @type {symbol}
|
925 | */
|
926 | static KEY: typeof entity.KEY_SYMBOL;
|
927 | KEY: typeof entity.KEY_SYMBOL;
|
928 | /**
|
929 | * This is one of three values which may be returned from
|
930 | * {@link Datastore#runQuery}, {@link Transaction#runQuery}, and
|
931 | * {@link Query#run} as `info.moreResults`.
|
932 | *
|
933 | * There *may* be more results after the specified end cursor.
|
934 | *
|
935 | * @type {string}
|
936 | */
|
937 | static MORE_RESULTS_AFTER_CURSOR: string;
|
938 | MORE_RESULTS_AFTER_CURSOR: string;
|
939 | /**
|
940 | * This is one of three values which may be returned from
|
941 | * {@link Datastore#runQuery}, {@link Transaction#runQuery}, and
|
942 | * {@link Query#run} as `info.moreResults`.
|
943 | *
|
944 | * There *may* be more results after the specified limit.
|
945 | *
|
946 | * @type {string}
|
947 | */
|
948 | static MORE_RESULTS_AFTER_LIMIT: string;
|
949 | MORE_RESULTS_AFTER_LIMIT: string;
|
950 | /**
|
951 | * This is one of three values which may be returned from
|
952 | * {@link Datastore#runQuery}, {@link Transaction#runQuery}, and
|
953 | * {@link Query#run} as `info.moreResults`.
|
954 | *
|
955 | * There are no more results left to query for.
|
956 | *
|
957 | * @type {string}
|
958 | */
|
959 | static NO_MORE_RESULTS: string;
|
960 | NO_MORE_RESULTS: string;
|
961 | /**
|
962 | * Create a query for the specified kind. See {@link Query} for all
|
963 | * of the available methods.
|
964 | *
|
965 | * @see {@link https://cloud.google.com/datastore/docs/concepts/queries| Datastore Queries}
|
966 | * @see {@link Query}
|
967 | *
|
968 | * @param {string} [namespace] Namespace.
|
969 | * @param {string} kind The kind to query.
|
970 | * @returns {Query}
|
971 | *
|
972 | * @example
|
973 | * ```
|
974 | * const {Datastore} = require('@google-cloud/datastore');
|
975 | * const datastore = new Datastore();
|
976 | * const query = datastore.createQuery('Company');
|
977 | * ```
|
978 | */
|
979 | createQuery(kind?: string): Query;
|
980 | createQuery(kind?: string[]): Query;
|
981 | createQuery(namespace: string, kind: string): Query;
|
982 | createQuery(namespace: string, kind: string[]): Query;
|
983 | /**
|
984 | * Helper to create a Key object, scoped to the instance's namespace by
|
985 | * default.
|
986 | *
|
987 | * You may also specify a configuration object to define a namespace and path.
|
988 | *
|
989 | * @param {object|string|array} [options] Key path. To specify or override a namespace,
|
990 | * you must use an object here to explicitly state it.
|
991 | * @param {string|array} [options.path] Key path.
|
992 | * @param {string} [options.namespace] Optional namespace.
|
993 | * @returns {Key} A newly created Key from the options given.
|
994 | *
|
995 | * @example
|
996 | * ```
|
997 | * <caption>Create an incomplete key with a kind value of `Company`.
|
998 | * Since no Id is supplied, Datastore will generate one on save.</caption>
|
999 | * const {Datastore} = require('@google-cloud/datastore');
|
1000 | * const datastore = new Datastore();
|
1001 | * const key = datastore.key('Company');
|
1002 | *
|
1003 | * ```
|
1004 | * @example
|
1005 | * ```
|
1006 | * <caption>Create a complete key with a kind value of `Company` and Id `123`.</caption>
|
1007 | * const {Datastore} = require('@google-cloud/datastore');
|
1008 | * const datastore = new Datastore();
|
1009 | * const key = datastore.key(['Company', 123]);
|
1010 | *
|
1011 | * ```
|
1012 | * @example
|
1013 | * ```
|
1014 | * <caption>If the ID integer is outside the bounds of a JavaScript Number
|
1015 | * object, create an Int.</caption>
|
1016 | * const {Datastore} = require('@google-cloud/datastore');
|
1017 | * const datastore = new Datastore();
|
1018 | * const key = datastore.key([
|
1019 | * 'Company',
|
1020 | * datastore.int('100000000000001234')
|
1021 | * ]);
|
1022 | *
|
1023 | * ```
|
1024 | * @example
|
1025 | * ```
|
1026 | * <caption>Create a complete key with a kind value of `Company` and name `Google`.
|
1027 | * Because the supplied Id is a string, Datastore will prefix it with "name=".
|
1028 | * Had the supplied Id been numeric, Datastore would prefix it with the standard, "id=".</caption>
|
1029 | * const {Datastore} = require('@google-cloud/datastore');
|
1030 | * const datastore = new Datastore();
|
1031 | * const key = datastore.key(['Company', 'Google']);
|
1032 | *
|
1033 | * ```
|
1034 | * @example
|
1035 | * ```
|
1036 | * <caption>Create a complete key from a provided namespace and path.</caption>
|
1037 | * const {Datastore} = require('@google-cloud/datastore');
|
1038 | * const datastore = new Datastore();
|
1039 | * const key = datastore.key({
|
1040 | * namespace: 'My-NS',
|
1041 | * path: ['Company', 123]
|
1042 | * });
|
1043 | *
|
1044 | * ```
|
1045 | * @example
|
1046 | * ```
|
1047 | * <caption>Create a complete key that specifies an ancestor. This will create a Team entity
|
1048 | * with a name of "Datastore", which belongs to the Company with the "name=Google" key.</caption>
|
1049 | * const {Datastore} = require('@google-cloud/datastore');
|
1050 | * const datastore = new Datastore();
|
1051 | * const key = datastore.key(['Company', 'Google', 'Team', 'Datastore']);
|
1052 | *
|
1053 | * ```
|
1054 | * @example
|
1055 | * ```
|
1056 | * <caption>Create a incomplete key that specifies an ancestor. This will create an Employee entity
|
1057 | * with an auto-generated Id, which belongs to the Company with the "name=Google" key.</caption>
|
1058 | * const {Datastore} = require('@google-cloud/datastore');
|
1059 | * const datastore = new Datastore();
|
1060 | * const key = datastore.key(['Company', 'Google', 'Employee']);
|
1061 | * ```
|
1062 | */
|
1063 | key(options: entity.KeyOptions): entity.Key;
|
1064 | key(path: PathType[]): entity.Key;
|
1065 | key(path: string): entity.Key;
|
1066 | /**
|
1067 | * Helper function to check if something is a Datastore Key object.
|
1068 | *
|
1069 | * @param {*} value
|
1070 | * @returns {boolean}
|
1071 | *
|
1072 | * @example
|
1073 | * ```
|
1074 | * const {Datastore} = require('@google-cloud/datastore');
|
1075 | * const datastore = new Datastore();
|
1076 | * datastore.isKey({path: ['Company', 123]}); // false
|
1077 | * datastore.isKey(datastore.key(['Company', 123])); // true
|
1078 | * ```
|
1079 | */
|
1080 | static isKey(value?: {}): value is entity.Key;
|
1081 | isKey(value?: {}): value is entity.Key;
|
1082 | /**
|
1083 | * Helper to create a URL safe key.
|
1084 | *
|
1085 | * This is intended to work with the "legacy" representation of a
|
1086 | * datastore "Key" used within Google App Engine (a so-called "Reference").
|
1087 | * The returned string can be used as the "urlsafe"
|
1088 | * The base64 encoded values will have padding removed.
|
1089 | *
|
1090 | *
|
1091 | * @param {entity.Key} key Entity key object.
|
1092 | * @param {string} locationPrefix Optional .
|
1093 | * The location prefix of an App Engine project ID.
|
1094 | * Often this value is 's~', but may also be 'e~', or other location prefixes
|
1095 | * currently unknown.
|
1096 | * @param {function} callback The callback function.
|
1097 | * @param {?error} callback.err An error returned while making this request
|
1098 | * @param {string} callback.urlSafeKey A Base64-encoded URL-safe key.
|
1099 | *
|
1100 | * @example
|
1101 | * ```
|
1102 | * const {Datastore} = require('@google-cloud/datastore');
|
1103 | * const datastore = new Datastore();
|
1104 | * const key = datastore.key(['Company', 'Google']);
|
1105 | *
|
1106 | * datastore.keyToLegacyUrlSafe(key, (err, urlSafeKey) => {
|
1107 | * if (err) {
|
1108 | * // Error handling omitted.
|
1109 | * }
|
1110 | * console.log(urlSafeKey);
|
1111 | * });
|
1112 | *
|
1113 | * //-
|
1114 | * // Create a complete URL-safe key using a location prefix.
|
1115 | * //-
|
1116 | * const locationPrefix = 's~';
|
1117 | *
|
1118 | * datastore.keyToLegacyUrlSafe(key, locationPrefix, (err, urlSafeKey) => {
|
1119 | * if (err) {
|
1120 | * // Error handling omitted.
|
1121 | * }
|
1122 | * console.log(urlSafeKey);
|
1123 | * });
|
1124 | *
|
1125 | * //-
|
1126 | * // If the callback is omitted, we'll return a Promise.
|
1127 | * //-
|
1128 | * datastore.keyToLegacyUrlSafe(key).then((data) => {
|
1129 | * const urlSafeKey = data[0];
|
1130 | * console.log(urlSafeKey);
|
1131 | * });
|
1132 | * ```
|
1133 | */
|
1134 | keyToLegacyUrlSafe(key: entity.Key, locationPrefix?: string): Promise<string>;
|
1135 | keyToLegacyUrlSafe(key: entity.Key, callback: KeyToLegacyUrlSafeCallback): void;
|
1136 | keyToLegacyUrlSafe(key: entity.Key, locationPrefix: string, callback: KeyToLegacyUrlSafeCallback): void;
|
1137 | /**
|
1138 | * Helper to convert URL safe key string to entity key object
|
1139 | *
|
1140 | * This is intended to work with the "legacy" representation of a
|
1141 | * datastore "Key" used within Google App Engine (a so-called "Reference").
|
1142 | *
|
1143 | * @param {entity.Key} key Entity key object.
|
1144 | * @param {string} locationPrefix Optional .
|
1145 | * The location prefix of an App Engine project ID.
|
1146 | * Often this value is 's~', but may also be 'e~', or other location prefixes
|
1147 | * currently unknown.
|
1148 | * @returns {string} Created urlsafe key.
|
1149 | *
|
1150 | * @example
|
1151 | * ```
|
1152 | * const {Datastore} = require('@google-cloud/datastore');
|
1153 | * const datastore = new Datastore();
|
1154 | * const urlSafeKey = 'ag9ncmFzcy1jbHVtcC00NzlyEwsSB0NvbXBhbnkiBkdvb2dsZQw';
|
1155 | *
|
1156 | * datastore.keyFromLegacyUrlsafe(key);
|
1157 | *
|
1158 | * ```
|
1159 | */
|
1160 | keyFromLegacyUrlsafe(key: string): entity.Key;
|
1161 | /**
|
1162 | * Create a new Transaction object.
|
1163 | *
|
1164 | * @param {object} [options] Configuration object.
|
1165 | * @param {string} [options.id] The ID of a previously run transaction.
|
1166 | * @param {boolean} [options.readOnly=false] A read-only transaction cannot
|
1167 | * modify entities.
|
1168 | * @returns {Transaction}
|
1169 | *
|
1170 | * @example
|
1171 | * ```
|
1172 | * const {Datastore} = require('@google-cloud/datastore');
|
1173 | * const datastore = new Datastore();
|
1174 | * const transaction = datastore.transaction();
|
1175 | * ```
|
1176 | */
|
1177 | transaction(options?: TransactionOptions): Transaction;
|
1178 | /**
|
1179 | * Determine the appropriate endpoint to use for API requests. If not
|
1180 | * explicitly defined, check for the "DATASTORE_EMULATOR_HOST" environment
|
1181 | * variable, used to connect to a local Datastore server.
|
1182 | *
|
1183 | * @private
|
1184 | *
|
1185 | * @param {string} customApiEndpoint Custom API endpoint.
|
1186 | */
|
1187 | determineBaseUrl_(customApiEndpoint?: string): void;
|
1188 | /**
|
1189 | * {@link DatastoreRequest} class.
|
1190 | *
|
1191 | * @name Datastore.DatastoreRequest
|
1192 | * @see DatastoreRequest
|
1193 | * @type {constructor}
|
1194 | */
|
1195 | DatastoreRequest: typeof DatastoreRequest;
|
1196 | /**
|
1197 | * {@link Query} class.
|
1198 | *
|
1199 | * @name Datastore.Query
|
1200 | * @see Query
|
1201 | * @type {constructor}
|
1202 | */
|
1203 | Query: typeof Query;
|
1204 | /**
|
1205 | * {@link Transaction} class.
|
1206 | *
|
1207 | * @name Datastore.Transaction
|
1208 | * @see Transaction
|
1209 | * @type {constructor}
|
1210 | */
|
1211 | Transaction: typeof Transaction;
|
1212 | }
|
1213 | export { Datastore };
|
1214 | export interface TransactionOptions {
|
1215 | id?: string;
|
1216 | readOnly?: boolean;
|
1217 | }
|
1218 | export { Index, DatastoreRequest, Query, Transaction };
|
1219 | export interface DatastoreOptions extends GoogleAuthOptions {
|
1220 | namespace?: string;
|
1221 | apiEndpoint?: string;
|
1222 | sslCreds?: ChannelCredentials;
|
1223 | databaseId?: string;
|
1224 | fallback?: Fallback;
|
1225 | }
|
1226 | export interface KeyToLegacyUrlSafeCallback {
|
1227 | (err?: Error | null, urlSafeKey?: string): void;
|
1228 | }
|
1229 | declare const v1: any;
|
1230 | export { v1 };
|
1231 | export { DatastoreClient, DatastoreAdminClient } from './v1';
|