@google-cloud/spanner 5.15.1 → 5.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -106,10 +106,12 @@ export interface RestoreOptions {
106
106
  * The default query options to use for queries on the database.
107
107
  *
108
108
  * @example
109
+ * ```
109
110
  * const {Spanner} = require('@google-cloud/spanner');
110
111
  * const spanner = new Spanner();
111
112
  * const instance = spanner.instance('my-instance');
112
113
  * const database = instance.database('my-database');
114
+ * ```
113
115
  */
114
116
  declare class Database extends common.GrpcServiceObject {
115
117
  private instance;
@@ -122,6 +124,68 @@ declare class Database extends common.GrpcServiceObject {
122
124
  request: DatabaseRequest;
123
125
  constructor(instance: Instance, name: string, poolOptions?: SessionPoolConstructor | SessionPoolOptions, queryOptions?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions);
124
126
  static getEnvironmentQueryOptions(): databaseAdmin.spanner.v1.ExecuteSqlRequest.IQueryOptions;
127
+ /**
128
+ * @typedef {object} BatchCreateSessionsOptions
129
+ * @property {number} count The number of sessions to create.
130
+ * @property {object.<string, string>} [labels] Labels to apply to each
131
+ * session.
132
+ * @property {object} [gaxOptions] Request configuration options,
133
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
134
+ * for more details.
135
+ */
136
+ /**
137
+ * @typedef {array} BatchCreateSessionsResponse
138
+ * @property {Session[]} 0 The newly created sessions.
139
+ * @property {object} 1 The full API response.
140
+ */
141
+ /**
142
+ * @callback BatchCreateSessionsCallback
143
+ * @param {?Error} err Request error, if any.
144
+ * @param {Session[]} sessions The newly created sessions.
145
+ * @param {object} apiResponse The full API response.
146
+ */
147
+ /**
148
+ * Create a batch of sessions, which can be used to perform transactions that
149
+ * read and/or modify data.
150
+ *
151
+ * **It is unlikely you will need to interact with sessions directly. By
152
+ * default, sessions are created and utilized for maximum performance
153
+ * automatically.**
154
+ *
155
+ * Wrapper around {@link v1.SpannerClient#batchCreateSessions}.
156
+ *
157
+ * @see {@link v1.SpannerClient#batchCreateSessions}
158
+ * @see [BatchCreateSessions API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.BatchCreateSessions)
159
+ *
160
+ * @param {number|BatchCreateSessionsOptions} options Desired session count or
161
+ * a configuration object.
162
+ * @param {BatchCreateSessionsCallback} [callback] Callback function.
163
+ * @returns {Promise<BatchCreateSessionsResponse>}
164
+ *
165
+ * @example
166
+ * ```
167
+ * const {Spanner} = require('@google-cloud/spanner');
168
+ * const spanner = new Spanner();
169
+ *
170
+ * const instance = spanner.instance('my-instance');
171
+ * const database = instance.database('my-database');
172
+ *
173
+ * const count = 5;
174
+ *
175
+ * database.batchCreateSession(count, (err, sessions, response) => {
176
+ * if (err) {
177
+ * // Error handling omitted.
178
+ * }
179
+ *
180
+ * // `sessions` is an array of Session objects.
181
+ * });
182
+ *
183
+ * ```
184
+ * @example If the callback is omitted, we'll return a Promise.
185
+ * ```
186
+ * const [sessions, response] = await database.batchCreateSessions(count);
187
+ * ```
188
+ */
125
189
  batchCreateSessions(options: number | BatchCreateSessionsOptions): Promise<BatchCreateSessionsResponse>;
126
190
  batchCreateSessions(options: number | BatchCreateSessionsOptions, callback: BatchCreateSessionsCallback): void;
127
191
  /**
@@ -134,6 +198,7 @@ declare class Database extends common.GrpcServiceObject {
134
198
  * @returns {BatchTransaction} A batch transaction object.
135
199
  *
136
200
  * @example
201
+ * ```
137
202
  * const {Spanner} = require('@google-cloud/spanner');
138
203
  * const spanner = new Spanner();
139
204
  *
@@ -145,16 +210,217 @@ declare class Database extends common.GrpcServiceObject {
145
210
  * transaction: 'my-transaction',
146
211
  * readTimestamp: 1518464696657
147
212
  * });
213
+ * ```
148
214
  */
149
215
  batchTransaction(identifier: TransactionIdentifier, options?: TimestampBounds): BatchTransaction;
216
+ /**
217
+ * @callback CloseDatabaseCallback
218
+ * @param {?Error} err Request error, if any.
219
+ */
220
+ /**
221
+ * Close the database connection and destroy all sessions associated with it.
222
+ *
223
+ * @param {CloseDatabaseCallback} [callback] Callback function.
224
+ * @returns {Promise}
225
+ *
226
+ * @example
227
+ * ```
228
+ * const {Spanner} = require('@google-cloud/spanner');
229
+ * const spanner = new Spanner();
230
+ *
231
+ * const instance = spanner.instance('my-instance');
232
+ * const database = instance.database('my-database');
233
+ *
234
+ * database.close(function(err) {
235
+ * if (err) {
236
+ * // Error handling omitted.
237
+ * }
238
+ * });
239
+ *
240
+ * //-
241
+ * // In the event of a session leak, the error object will contain a
242
+ * // `messages` field.
243
+ * //-
244
+ * database.close(function(err) {
245
+ * if (err && err.messages) {
246
+ * err.messages.forEach(function(message) {
247
+ * console.error(message);
248
+ * });
249
+ * }
250
+ * });
251
+ * ```
252
+ */
150
253
  close(callback: SessionPoolCloseCallback): void;
151
254
  close(): Promise<DatabaseCloseResponse>;
255
+ /**
256
+ * @typedef {array} CreateTransactionResponse
257
+ * @property {BatchTransaction} 0 The {@link BatchTransaction}.
258
+ * @property {object} 1 The full API response.
259
+ */
260
+ /**
261
+ * @callback CreateTransactionCallback
262
+ * @param {?Error} err Request error, if any.
263
+ * @param {BatchTransaction} transaction The {@link BatchTransaction}.
264
+ * @param {object} apiResponse The full API response.
265
+ */
266
+ /**
267
+ * Create a transaction that can be used for batch querying.
268
+ *
269
+ * @param {object} [options] [Transaction options](https://cloud.google.com/spanner/docs/timestamp-bounds).
270
+ * @param {CreateTransactionCallback} [callback] Callback function.
271
+ * @returns {Promise<CreateTransactionResponse>}
272
+ */
152
273
  createBatchTransaction(options?: TimestampBounds): Promise<CreateBatchTransactionResponse>;
153
274
  createBatchTransaction(callback: CreateBatchTransactionCallback): void;
154
275
  createBatchTransaction(options: TimestampBounds, callback: CreateBatchTransactionCallback): void;
276
+ /**
277
+ * Create a new session.
278
+ *
279
+ * @typedef {object} CreateSessionOptions
280
+ * @property {Object.<string, string>} [labels] The labels for the session.
281
+ *
282
+ * * Label keys must be between 1 and 63 characters long and must conform to
283
+ * the following regular expression: `[a-z]([-a-z0-9]*[a-z0-9])?`.
284
+ * * Label values must be between 0 and 63 characters long and must conform
285
+ * to the regular expression `([a-z]([-a-z0-9]*[a-z0-9])?)?`.
286
+ * * No more than 64 labels can be associated with a given session.
287
+ * @property {object} [gaxOptions] Request configuration options,
288
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
289
+ * for more details.
290
+ */
291
+ /**
292
+ * @typedef {array} CreateSessionResponse
293
+ * @property {Session} 0 The newly created session.
294
+ * @property {object} 1 The full API response.
295
+ */
296
+ /**
297
+ * @callback CreateSessionCallback
298
+ * @param {?Error} err Request error, if any.
299
+ * @param {Session} session The newly created session.
300
+ * @param {object} apiResponse The full API response.
301
+ */
302
+ /**
303
+ * Create a new session, which can be used to perform transactions that read
304
+ * and/or modify data.
305
+ *
306
+ * Sessions can only execute one transaction at a time. To execute multiple
307
+ * concurrent read-write/write-only transactions, create multiple sessions.
308
+ * Note that standalone reads and queries use a transaction internally, and
309
+ * count toward the one transaction limit.
310
+ *
311
+ * **It is unlikely you will need to interact with sessions directly. By
312
+ * default, sessions are created and utilized for maximum performance
313
+ * automatically.**
314
+ *
315
+ * Wrapper around {@link v1.SpannerClient#createSession}.
316
+ *
317
+ * @see {@link v1.SpannerClient#createSession}
318
+ * @see [CreateSession API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.CreateSession)
319
+ *
320
+ * @param {CreateSessionOptions} [options] Configuration object.
321
+ * @param {CreateSessionCallback} [callback] Callback function.
322
+ * @returns {Promise<CreateSessionResponse>}
323
+ *
324
+ * @example
325
+ * ```
326
+ * const {Spanner} = require('@google-cloud/spanner');
327
+ * const spanner = new Spanner();
328
+ *
329
+ * const instance = spanner.instance('my-instance');
330
+ * const database = instance.database('my-database');
331
+ *
332
+ * database.createSession(function(err, session, apiResponse) {
333
+ * if (err) {
334
+ * // Error handling omitted.
335
+ * }
336
+ *
337
+ * // `session` is a Session object.
338
+ * });
339
+ *
340
+ * //-
341
+ * // If the callback is omitted, we'll return a Promise.
342
+ * //-
343
+ * database.createSession().then(function(data) {
344
+ * const session = data[0];
345
+ * const apiResponse = data[1];
346
+ * });
347
+ * ```
348
+ */
155
349
  createSession(options: CreateSessionOptions): Promise<CreateSessionResponse>;
156
350
  createSession(callback: CreateSessionCallback): void;
157
351
  createSession(options: CreateSessionOptions, callback: CreateSessionCallback): void;
352
+ /**
353
+ * @typedef {array} CreateTableResponse
354
+ * @property {Table} 0 The new {@link Table}.
355
+ * @property {google.longrunning.Operation} 1 An {@link Operation} object that can be used to check
356
+ * the status of the request.
357
+ * @property {object} 2 The full API response.
358
+ */
359
+ /**
360
+ * @callback CreateTableCallback
361
+ * @param {?Error} err Request error, if any.
362
+ * @param {Table} table The new {@link Table}.
363
+ * @param {google.longrunning.Operation} operation An {@link Operation} object that can be used to
364
+ * check the status of the request.
365
+ * @param {object} apiResponse The full API response.
366
+ */
367
+ /**
368
+ * Create a table.
369
+ *
370
+ * Wrapper around {@link Database#updateSchema}.
371
+ *
372
+ * @see {@link Database#updateSchema}
373
+ *
374
+ * @param {string} schema A DDL CREATE statement describing the table.
375
+ * @param {object} [gaxOptions] Request configuration options,
376
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
377
+ * for more details.
378
+ * @param {CreateTableCallback} [callback] Callback function.
379
+ * @returns {Promise<CreateTableResponse>}
380
+ *
381
+ * @example
382
+ * ```
383
+ * const {Spanner} = require('@google-cloud/spanner');
384
+ * const spanner = new Spanner();
385
+ *
386
+ * const instance = spanner.instance('my-instance');
387
+ * const database = instance.database('my-database');
388
+ *
389
+ * const schema =
390
+ * 'CREATE TABLE Singers (' +
391
+ * ' SingerId INT64 NOT NULL,' +
392
+ * ' FirstName STRING(1024),' +
393
+ * ' LastName STRING(1024),' +
394
+ * ' SingerInfo BYTES(MAX),' +
395
+ * ') PRIMARY KEY(SingerId)';
396
+ *
397
+ * database.createTable(schema, function(err, table, operation, apiResponse) {
398
+ * if (err) {
399
+ * // Error handling omitted.
400
+ * }
401
+ *
402
+ * operation
403
+ * .on('error', function(err) {})
404
+ * .on('complete', function() {
405
+ * // Table created successfully.
406
+ * });
407
+ * });
408
+ *
409
+ * //-
410
+ * // If the callback is omitted, we'll return a Promise.
411
+ * //-
412
+ * database.createTable(schema)
413
+ * .then(function(data) {
414
+ * const table = data[0];
415
+ * const operation = data[1];
416
+ *
417
+ * return operation.promise();
418
+ * })
419
+ * .then(function() {
420
+ * // Table created successfully.
421
+ * });
422
+ * ```
423
+ */
158
424
  createTable(schema: Schema, gaxOptions?: CallOptions): Promise<CreateTableResponse>;
159
425
  createTable(schema: Schema, callback: CreateTableCallback): void;
160
426
  createTable(schema: Schema, gaxOptions: CallOptions, callback: CreateTableCallback): void;
@@ -168,28 +434,409 @@ declare class Database extends common.GrpcServiceObject {
168
434
  * @param {Transaction} transaction The transaction to observe.
169
435
  * @returns {Transaction}
170
436
  */
171
- private _releaseOnEnd;
172
- delete(gaxOptions?: CallOptions): Promise<DatabaseDeleteResponse>;
173
- delete(callback: DatabaseDeleteCallback): void;
174
- delete(gaxOptions: CallOptions, callback: DatabaseDeleteCallback): void;
175
- exists(gaxOptions?: CallOptions): Promise<[boolean]>;
176
- exists(callback: ExistsCallback): void;
177
- exists(gaxOptions: CallOptions, callback: ExistsCallback): void;
178
- get(options?: GetDatabaseConfig): Promise<DatabaseResponse>;
179
- get(callback: DatabaseCallback): void;
180
- get(options: GetDatabaseConfig, callback: DatabaseCallback): void;
181
- getMetadata(gaxOptions?: CallOptions): Promise<GetDatabaseMetadataResponse>;
182
- getMetadata(callback: GetDatabaseMetadataCallback): void;
183
- getMetadata(gaxOptions: CallOptions, callback: GetDatabaseMetadataCallback): void;
184
- getRestoreInfo(options?: CallOptions): Promise<IRestoreInfoTranslatedEnum | undefined>;
185
- getRestoreInfo(callback: GetRestoreInfoCallback): void;
186
- getRestoreInfo(options: CallOptions, callback: GetRestoreInfoCallback): void;
187
- getState(options?: CallOptions): Promise<EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Database.State> | undefined>;
188
- getState(callback: GetStateCallback): void;
189
- getState(options: CallOptions, callback: GetStateCallback): void;
190
- getSchema(options?: CallOptions): Promise<GetSchemaResponse>;
191
- getSchema(callback: GetSchemaCallback): void;
192
- getSchema(options: CallOptions, callback: GetSchemaCallback): void;
437
+ private _releaseOnEnd;
438
+ /**
439
+ * @typedef {array} DatabaseDeleteResponse
440
+ * @property {object} 0 The full API response.
441
+ */
442
+ /**
443
+ * @callback DatabaseDeleteCallback
444
+ * @param {?Error} err Request error, if any.
445
+ * @param {object} apiResponse The full API response.
446
+ */
447
+ /**
448
+ * Delete the database.
449
+ *
450
+ * Wrapper around {@link v1.DatabaseAdminClient#dropDatabase}.
451
+ *
452
+ * @see {@link v1.DatabaseAdminClient#dropDatabase}
453
+ * @see [DropDatabase API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase)
454
+ *
455
+ * @param {object} [gaxOptions] Request configuration options,
456
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
457
+ * for more details.
458
+ * @param {DatabaseDeleteCallback} [callback] Callback function.
459
+ * @returns {Promise<DatabaseDeleteResponse>}
460
+ *
461
+ * @example
462
+ * ```
463
+ * const {Spanner} = require('@google-cloud/spanner');
464
+ * const spanner = new Spanner();
465
+ *
466
+ * const instance = spanner.instance('my-instance');
467
+ * const database = instance.database('my-database');
468
+ *
469
+ * database.delete(function(err, apiResponse) {
470
+ * if (err) {
471
+ * // Error handling omitted.
472
+ * }
473
+ *
474
+ * // Database was deleted successfully.
475
+ * });
476
+ *
477
+ * //-
478
+ * // If the callback is omitted, we'll return a Promise.
479
+ * //-
480
+ * database.delete().then(function(data) {
481
+ * const apiResponse = data[0];
482
+ * });
483
+ * ```
484
+ */
485
+ delete(gaxOptions?: CallOptions): Promise<DatabaseDeleteResponse>;
486
+ delete(callback: DatabaseDeleteCallback): void;
487
+ delete(gaxOptions: CallOptions, callback: DatabaseDeleteCallback): void;
488
+ /**
489
+ * @typedef {array} DatabaseExistsResponse
490
+ * @property {boolean} 0 Whether the {@link Database} exists.
491
+ */
492
+ /**
493
+ * @callback DatabaseExistsCallback
494
+ * @param {?Error} err Request error, if any.
495
+ * @param {boolean} exists Whether the {@link Database} exists.
496
+ */
497
+ /**
498
+ * Check if a database exists.
499
+ *
500
+ * @method Database#exists
501
+ * @param {object} [gaxOptions] Request configuration options,
502
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
503
+ * for more details.
504
+ * @param {DatabaseExistsCallback} [callback] Callback function.
505
+ * @returns {Promise<DatabaseExistsResponse>}
506
+ *
507
+ * @example
508
+ * ```
509
+ * const {Spanner} = require('@google-cloud/spanner');
510
+ * const spanner = new Spanner();
511
+ *
512
+ * const instance = spanner.instance('my-instance');
513
+ * const database = instance.database('my-database');
514
+ *
515
+ * database.exists(function(err, exists) {});
516
+ *
517
+ * //-
518
+ * // If the callback is omitted, we'll return a Promise.
519
+ * //-
520
+ * database.exists().then(function(data) {
521
+ * const exists = data[0];
522
+ * });
523
+ * ```
524
+ */
525
+ exists(gaxOptions?: CallOptions): Promise<[boolean]>;
526
+ exists(callback: ExistsCallback): void;
527
+ exists(gaxOptions: CallOptions, callback: ExistsCallback): void;
528
+ /**
529
+ * @typedef {array} GetDatabaseResponse
530
+ * @property {Database} 0 The {@link Database}.
531
+ * @property {object} 1 The full API response.
532
+ */
533
+ /**
534
+ * @callback GetDatabaseCallback
535
+ * @param {?Error} err Request error, if any.
536
+ * @param {Database} database The {@link Database}.
537
+ * @param {object} apiResponse The full API response.
538
+ */
539
+ /**
540
+ * Get a database if it exists.
541
+ *
542
+ * You may optionally use this to "get or create" an object by providing an
543
+ * object with `autoCreate` set to `true`. Any extra configuration that is
544
+ * normally required for the `create` method must be contained within this
545
+ * object as well.
546
+ *
547
+ * @param {options} [options] Configuration object.
548
+ * @param {boolean} [options.autoCreate=false] Automatically create the
549
+ * object if it does not exist.
550
+ * @param {object} [options.gaxOptions] Request configuration options,
551
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
552
+ * for more details.
553
+ * @param {GetDatabaseCallback} [callback] Callback function.
554
+ * @returns {Promise<GetDatabaseResponse>}
555
+ *
556
+ * @example
557
+ * ```
558
+ * const {Spanner} = require('@google-cloud/spanner');
559
+ * const spanner = new Spanner();
560
+ *
561
+ * const instance = spanner.instance('my-instance');
562
+ * const database = instance.database('my-database');
563
+ *
564
+ * database.get(function(err, database, apiResponse) {
565
+ * // `database.metadata` has been populated.
566
+ * });
567
+ *
568
+ * //-
569
+ * // If the callback is omitted, we'll return a Promise.
570
+ * //-
571
+ * database.get().then(function(data) {
572
+ * const database = data[0];
573
+ * const apiResponse = data[0];
574
+ * });
575
+ * ```
576
+ */
577
+ get(options?: GetDatabaseConfig): Promise<DatabaseResponse>;
578
+ get(callback: DatabaseCallback): void;
579
+ get(options: GetDatabaseConfig, callback: DatabaseCallback): void;
580
+ /**
581
+ * @typedef {array} GetDatabaseMetadataResponse
582
+ * @property {object} 0 The {@link Database} metadata.
583
+ * @property {object} 1 The full API response.
584
+ */
585
+ /**
586
+ * @callback GetDatabaseMetadataCallback
587
+ * @param {?Error} err Request error, if any.
588
+ * @param {object} metadata The {@link Database} metadata.
589
+ * @param {object} apiResponse The full API response.
590
+ */
591
+ /**
592
+ * Get the database's metadata.
593
+ *
594
+ * Wrapper around {@link v1.DatabaseAdminClient#getDatabase}.
595
+ *
596
+ * @see {@link v1.DatabaseAdminClient#getDatabase}
597
+ * @see [GetDatabase API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase)
598
+ * @param {object} [gaxOptions] Request configuration options,
599
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
600
+ * for more details.
601
+ * @param {GetDatabaseMetadataCallback} [callback] Callback function.
602
+ * @returns {Promise<GetDatabaseMetadataResponse>}
603
+ *
604
+ * @example
605
+ * ```
606
+ * const {Spanner} = require('@google-cloud/spanner');
607
+ * const spanner = new Spanner();
608
+ *
609
+ * const instance = spanner.instance('my-instance');
610
+ * const database = instance.database('my-database');
611
+ *
612
+ * database.getMetadata(function(err, metadata) {
613
+ * if (err) {
614
+ * // Error handling omitted.
615
+ * }
616
+ *
617
+ * // Database was deleted successfully.
618
+ * });
619
+ *
620
+ * //-
621
+ * // If the callback is omitted, we'll return a Promise.
622
+ * //-
623
+ * database.getMetadata().then(function(data) {
624
+ * const metadata = data[0];
625
+ * const apiResponse = data[1];
626
+ * });
627
+ * ```
628
+ */
629
+ getMetadata(gaxOptions?: CallOptions): Promise<GetDatabaseMetadataResponse>;
630
+ getMetadata(callback: GetDatabaseMetadataCallback): void;
631
+ getMetadata(gaxOptions: CallOptions, callback: GetDatabaseMetadataCallback): void;
632
+ /**
633
+ * {@link google.spanner.admin.database.v1#RestoreInfo} structure with restore
634
+ * source type enum translated to string form.
635
+ *
636
+ * @typedef {object} IRestoreInfoTranslatedEnum
637
+ */
638
+ /**
639
+ * @callback GetRestoreInfoCallback
640
+ * @param {?Error} err Request error, if any.
641
+ * @param {IRestoreInfoTranslatedEnum | undefined} restoreInfo Contains the restore
642
+ * information for the database if it was restored from a backup.
643
+ */
644
+ /**
645
+ * Retrieves the restore information of the database.
646
+ *
647
+ * @see {@link #getMetadata}
648
+ *
649
+ * @method Database#getRestoreInfo
650
+ * @param {object} [gaxOptions] Request configuration options,
651
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
652
+ * for more details.
653
+ * @param {GetRestoreInfoCallback} [callback] Callback function.
654
+ * @returns {Promise<IRestoreInfoTranslatedEnum | undefined>} When resolved,
655
+ * contains the restore information for the database if it was restored
656
+ * from a backup.
657
+ *
658
+ * @example
659
+ * ```
660
+ * const {Spanner} = require('@google-cloud/spanner');
661
+ * const spanner = new Spanner();
662
+ * const instance = spanner.instance('my-instance');
663
+ * const database = instance.database('my-database');
664
+ * const restoreInfo = await database.getRestoreInfo();
665
+ * console.log(`Database restored from ${restoreInfo.backupInfo.backup}`);
666
+ * ```
667
+ */
668
+ getRestoreInfo(options?: CallOptions): Promise<IRestoreInfoTranslatedEnum | undefined>;
669
+ getRestoreInfo(callback: GetRestoreInfoCallback): void;
670
+ getRestoreInfo(options: CallOptions, callback: GetRestoreInfoCallback): void;
671
+ /**
672
+ * @callback GetStateCallback
673
+ * @param {?Error} err Request error, if any.
674
+ * @param {EnumKey<typeof, google.spanner.admin.database.v1.Database.State> | undefined} state
675
+ * Contains the current state of the database if the state is defined.
676
+ */
677
+ /**
678
+ * Retrieves the state of the database.
679
+ *
680
+ * The database state indicates if the database is ready after creation or
681
+ * after being restored from a backup.
682
+ *
683
+ * @see {@link #getMetadata}
684
+ *
685
+ * @method Database#getState
686
+ * @param {object} [gaxOptions] Request configuration options,
687
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
688
+ * for more details.
689
+ * @param {GetStateCallback} [callback] Callback function.
690
+ * @returns {Promise<EnumKey<typeof, google.spanner.admin.database.v1.Database.State> | undefined>}
691
+ * When resolved, contains the current state of the database if the state
692
+ * is defined.
693
+ *
694
+ * @example
695
+ * ```
696
+ * const {Spanner} = require('@google-cloud/spanner');
697
+ * const spanner = new Spanner();
698
+ * const instance = spanner.instance('my-instance');
699
+ * const database = instance.database('my-database');
700
+ * const state = await database.getState();
701
+ * const isReady = (state === 'READY');
702
+ * ```
703
+ */
704
+ getState(options?: CallOptions): Promise<EnumKey<typeof databaseAdmin.spanner.admin.database.v1.Database.State> | undefined>;
705
+ getState(callback: GetStateCallback): void;
706
+ getState(options: CallOptions, callback: GetStateCallback): void;
707
+ /**
708
+ * @typedef {array} GetSchemaResponse
709
+ * @property {string[]} 0 An array of database DDL statements.
710
+ * @property {object} 1 The full API response.
711
+ */
712
+ /**
713
+ * @callback GetSchemaCallback
714
+ * @param {?Error} err Request error, if any.
715
+ * @param {string[]} statements An array of database DDL statements.
716
+ * @param {object} apiResponse The full API response.
717
+ */
718
+ /**
719
+ * Get this database's schema as a list of formatted DDL statements.
720
+ *
721
+ * Wrapper around {@link v1.DatabaseAdminClient#getDatabaseDdl}.
722
+ *
723
+ * @see {@link v1.DatabaseAdminClient#getDatabaseDdl}
724
+ * @see [Data Definition Language (DDL)](https://cloud.google.com/spanner/docs/data-definition-language)
725
+ * @see [GetDatabaseDdl API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl)
726
+ *
727
+ * @param {object} [gaxOptions] Request configuration options,
728
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
729
+ * for more details.
730
+ * @param {GetSchemaCallback} [callback] Callback function.
731
+ * @returns {Promise<GetSchemaResponse>}
732
+ *
733
+ * @example
734
+ * ```
735
+ * const {Spanner} = require('@google-cloud/spanner');
736
+ * const spanner = new Spanner();
737
+ *
738
+ * const instance = spanner.instance('my-instance');
739
+ * const database = instance.database('my-database');
740
+ *
741
+ * database.getSchema(function(err, statements, apiResponse) {});
742
+ *
743
+ * //-
744
+ * // If the callback is omitted, we'll return a Promise.
745
+ * //-
746
+ * database.getSchema().then(function(data) {
747
+ * const statements = data[0];
748
+ * const apiResponse = data[1];
749
+ * });
750
+ * ```
751
+ */
752
+ getSchema(options?: CallOptions): Promise<GetSchemaResponse>;
753
+ getSchema(callback: GetSchemaCallback): void;
754
+ getSchema(options: CallOptions, callback: GetSchemaCallback): void;
755
+ /**
756
+ * Options object for listing sessions.
757
+ *
758
+ * @typedef {object} GetSessionsOptions
759
+ * @property {string} [filter] An expression for filtering the results of the
760
+ * request. Filter rules are case insensitive. The fields eligible for
761
+ * filtering are:
762
+ * - **`name`**
763
+ * - **`display_name`**
764
+ * - **`labels.key`** where key is the name of a label
765
+ *
766
+ * Some examples of using filters are:
767
+ * - **`name:*`** The instance has a name.
768
+ * - **`name:Howl`** The instance's name is howl.
769
+ * - **`labels.env:*`** The instance has the label env.
770
+ * - **`labels.env:dev`** The instance's label env has the value dev.
771
+ * - **`name:howl labels.env:dev`** The instance's name is howl and it has
772
+ * the label env with value dev.
773
+ * @property {number} [pageSize] Maximum number of results per page.
774
+ * @property {string} [pageToken] A previously-returned page token
775
+ * representing part of the larger set of results to view.
776
+ * @property {object} [gaxOptions] Request configuration options,
777
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
778
+ * for more details.
779
+ */
780
+ /**
781
+ * @typedef {array} GetSessionsResponse
782
+ * @property {Session[]} 0 Array of {@link Session} instances.
783
+ * @property {object} 1 A query object to receive more results.
784
+ * @property {object} 2 The full API response.
785
+ */
786
+ /**
787
+ * @callback GetSessionsCallback
788
+ * @param {?Error} err Request error, if any.
789
+ * @param {Session[]} instances Array of {@link Session} instances.
790
+ * @param {object} nextQuery A query object to receive more results.
791
+ * @param {object} apiResponse The full API response.
792
+ */
793
+ /**
794
+ * Gets a list of sessions.
795
+ *
796
+ * Wrapper around {@link v1.SpannerClient#listSessions}
797
+ *
798
+ * @see {@link v1.SpannerClient#listSessions}
799
+ * @see [ListSessions API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.ListSessions)
800
+ *
801
+ * @param {GetSessionsOptions} [options] Options object for listing sessions.
802
+ * @param {GetSessionsCallback} [callback] Callback function.
803
+ * @returns {Promise<GetSessionsResponse>}
804
+ *
805
+ * @example
806
+ * ```
807
+ * const {Spanner} = require('@google-cloud/spanner');
808
+ * const spanner = new Spanner();
809
+ *
810
+ * const instance = spanner.instance('my-instance');
811
+ * const database = instance.database('my-database');
812
+ *
813
+ * database.getSessions(function(err, sessions) {
814
+ * // `sessions` is an array of `Session` objects.
815
+ * });
816
+ *
817
+ * //-
818
+ * // To control how many API requests are made and page through the results
819
+ * // manually, set `autoPaginate` to `false`.
820
+ * //-
821
+ * function callback(err, sessions, nextQuery, apiResponse) {
822
+ * if (nextQuery) {
823
+ * // More results exist.
824
+ * database.getSessions(nextQuery, callback);
825
+ * }
826
+ * }
827
+ *
828
+ * database.getInstances({
829
+ * gaxOptions: {autoPaginate: false}
830
+ * }, callback);
831
+ *
832
+ * //-
833
+ * // If the callback is omitted, we'll return a Promise.
834
+ * //-
835
+ * database.getInstances().then(function(data) {
836
+ * const sessions = data[0];
837
+ * });
838
+ * ```
839
+ */
193
840
  getSessions(options?: GetSessionsOptions): Promise<GetSessionsResponse>;
194
841
  getSessions(callback: GetSessionsCallback): void;
195
842
  getSessions(options: GetSessionsOptions, callback: GetSessionsCallback): void;
@@ -207,6 +854,7 @@ declare class Database extends common.GrpcServiceObject {
207
854
  * instances.
208
855
  *
209
856
  * @example
857
+ * ```
210
858
  * const {Spanner} = require('@google-cloud/spanner');
211
859
  * const spanner = new Spanner();
212
860
  *
@@ -230,16 +878,184 @@ declare class Database extends common.GrpcServiceObject {
230
878
  * .on('data', function(session) {
231
879
  * this.end();
232
880
  * });
881
+ * ```
233
882
  */
234
883
  getSessionsStream(options?: GetSessionsOptions): NodeJS.ReadableStream;
884
+ /**
885
+ * @typedef {array} GetSnapshotResponse
886
+ * @property {Snapshot} 0 The snapshot object.
887
+ */
888
+ /**
889
+ * @callback GetSnapshotCallback
890
+ * @param {?Error} err Request error, if any.
891
+ * @param {Snapshot} snapshot The snapshot object.
892
+ */
893
+ /**
894
+ * Get a read only {@link Snapshot} transaction.
895
+ *
896
+ * Wrapper around {@link v1.SpannerClient#beginTransaction}.
897
+ *
898
+ * **NOTE:** When finished with the Snapshot, {@link Snapshot#end} should be
899
+ * called to release the underlying {@link Session}. **Failure to do could
900
+ * result in a Session leak.**
901
+ *
902
+ * **NOTE:** Since the returned {@link Snapshot} transaction is not a
903
+ * single-use transaction, it is invalid to set the `minReadTimestamp` and
904
+ * `maxStaleness` parameters in {@link TimestampBounds} as those parameters
905
+ * can only be set for single-use transactions.
906
+ * https://cloud.google.com/spanner/docs/reference/rest/v1/TransactionOptions#bounded-staleness
907
+ *
908
+ * @see {@link v1.SpannerClient#beginTransaction}
909
+ *
910
+ * @param {TimestampBounds} [options] Timestamp bounds.
911
+ * @param {GetSnapshotCallback} [callback] Callback function.
912
+ * @returns {Promise<GetSnapshotResponse>}
913
+ *
914
+ * @example
915
+ * ```
916
+ * const {Spanner} = require('@google-cloud/spanner');
917
+ * const spanner = new Spanner();
918
+ *
919
+ * const instance = spanner.instance('my-instance');
920
+ * const database = instance.database('my-database');
921
+ *
922
+ * database.getSnapshot(function(err, transaction) {
923
+ * if (err) {
924
+ * // Error handling omitted.
925
+ * }
926
+ *
927
+ * // Should be called when finished with Snapshot.
928
+ * transaction.end();
929
+ * });
930
+ * ```
931
+ *
932
+ * @example If the callback is omitted, we'll return a Promise.
933
+ * ```
934
+ * database.getSnapshot().then(function(data) {
935
+ * const transaction = data[0];
936
+ * });
937
+ * ```
938
+ *
939
+ * @example <caption>include:samples/transaction.js</caption>
940
+ * region_tag:spanner_read_only_transaction
941
+ * Read-only transaction:
942
+ */
235
943
  getSnapshot(options?: TimestampBounds): Promise<[Snapshot]>;
236
944
  getSnapshot(callback: GetSnapshotCallback): void;
237
945
  getSnapshot(options: TimestampBounds, callback: GetSnapshotCallback): void;
946
+ /**
947
+ * @typedef {array} GetTransactionResponse
948
+ * @property {Transaction} 0 The transaction object.
949
+ */
950
+ /**
951
+ * @callback GetTransactionCallback
952
+ * @param {?Error} err Request error, if any.
953
+ * @param {Transaction} transaction The transaction object.
954
+ */
955
+ /**
956
+ * Get a read/write ready {@link Transaction} object.
957
+ *
958
+ * **NOTE:** In the event that you encounter an error while reading/writing,
959
+ * if you decide to forgo calling {@link Transaction#commit} or
960
+ * {@link Transaction#rollback}, then you need to call
961
+ * {@link Transaction#end} to release the underlying {@link Session} object.
962
+ * **Failure to do could result in a Session leak.**
963
+ *
964
+ * Wrapper around {@link v1.SpannerClient#beginTransaction}.
965
+ *
966
+ * @see {@link v1.SpannerClient#beginTransaction}
967
+ *
968
+ * @param {GetTransactionCallback} [callback] Callback function.
969
+ * @returns {Promise<GetTransactionResponse>}
970
+ *
971
+ * @example
972
+ * ```
973
+ * const {Spanner} = require('@google-cloud/spanner');
974
+ * const spanner = new Spanner();
975
+ *
976
+ * const instance = spanner.instance('my-instance');
977
+ * const database = instance.database('my-database');
978
+ *
979
+ * database.getTransaction(function(err, transaction) {});
980
+ *
981
+ * ```
982
+ * @example If the callback is omitted, we'll return a Promise.
983
+ * ```
984
+ * database.getTransaction().then(function(data) {
985
+ * const transaction = data[0];
986
+ * });
987
+ * ```
988
+ */
238
989
  getTransaction(): Promise<[Transaction]>;
239
990
  getTransaction(callback: GetTransactionCallback): void;
991
+ /**
992
+ * Query object for listing database operations.
993
+ *
994
+ * @typedef {object} GetDatabaseOperationsOptions
995
+ * @property {string} [filter] An expression for filtering the results of the
996
+ * request. Filter can be configured as outlined in
997
+ * {@link v1.DatabaseAdminClient#listDatabaseOperations}.
998
+ * @property {number} [pageSize] Maximum number of results per page.
999
+ * @property {string} [pageToken] A previously-returned page token
1000
+ * representing part of the larger set of results to view.
1001
+ * @property {object} [gaxOptions] Request configuration options,
1002
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
1003
+ * for more details.
1004
+ * @param {GetDatabaseOperationsCallback} [callback] Callback function.
1005
+ */
1006
+ /**
1007
+ * @typedef {array} GetDatabaseOperationsResponse
1008
+ * @property {IOperation[]} 0 Array of {@link IOperation} instances.
1009
+ * @property {object} 1 The full API response.
1010
+ */
1011
+ /**
1012
+ * List pending and completed operations for the database.
1013
+ *
1014
+ * @see {@link Instance.getDatabaseOperations}
1015
+ *
1016
+ * @param {GetDatabaseOperationsOptions} [options] Contains query object for
1017
+ * listing database operations and request configuration options,
1018
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
1019
+ * for more details.
1020
+ * @returns {Promise<GetDatabaseOperationsResponse>} When resolved, contains
1021
+ * a paged list of database operations.
1022
+ *
1023
+ * @example
1024
+ * ```
1025
+ * const {Spanner} = require('@google-cloud/spanner');
1026
+ * const spanner = new Spanner();
1027
+ * const instance = spanner.instance('my-instance');
1028
+ * const database = instance.database('my-database');
1029
+ * const [operations] = await database.getOperations();
1030
+ *
1031
+ * //-
1032
+ * // To manually handle pagination, set autoPaginate:false in gaxOptions.
1033
+ * //-
1034
+ * let pageToken = undefined;
1035
+ * do {
1036
+ * const [operations, , response] = await database.getOperations({
1037
+ * pageSize: 3,
1038
+ * pageToken,
1039
+ * gaxOptions: {autoPaginate: false},
1040
+ * });
1041
+ * operations.forEach(operation => {
1042
+ * // Do something with operation
1043
+ * });
1044
+ * pageToken = response.nextPageToken;
1045
+ * } while (pageToken);
1046
+ * ```
1047
+ */
240
1048
  getOperations(options?: GetDatabaseOperationsOptions): Promise<GetDatabaseOperationsResponse>;
241
1049
  getOperations(callback: GetDatabaseOperationsCallback): void;
242
1050
  getOperations(options: GetDatabaseOperationsOptions, callback: GetDatabaseOperationsCallback): void;
1051
+ /**
1052
+ * Make an API request, first assuring an active session is used.
1053
+ *
1054
+ * @private
1055
+ *
1056
+ * @param {object} config Request config
1057
+ * @param {function} callback Callback function
1058
+ */
243
1059
  makePooledRequest_(config: RequestConfig): Promise<Session>;
244
1060
  makePooledRequest_(config: RequestConfig, callback: PoolRequestCallback): void;
245
1061
  /**
@@ -251,14 +1067,245 @@ declare class Database extends common.GrpcServiceObject {
251
1067
  * @returns {Stream}
252
1068
  */
253
1069
  makePooledStreamingRequest_(config: RequestConfig): Readable;
1070
+ /**
1071
+ * @typedef {object} RestoreOptions
1072
+ * @property {google.spanner.admin.database.v1.IRestoreDatabaseEncryptionConfig}
1073
+ * encryptionConfig An encryption configuration describing
1074
+ * the encryption type and key resources in Cloud KMS used to
1075
+ * encrypt/decrypt the database to restore to.
1076
+ * @property {CallOptions} [gaxOptions] The request configuration options,
1077
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
1078
+ * for more details.
1079
+ */
1080
+ /**
1081
+ * @typedef {array} RestoreDatabaseResponse
1082
+ * @property {Database} 0 The new {@link Database}.
1083
+ * @property {google.longrunning.Operation} 1 An {@link Operation} object that can be used to check
1084
+ * the status of the request.
1085
+ * @property {object} 2 The full API response.
1086
+ */
1087
+ /**
1088
+ * @callback RestoreDatabaseCallback
1089
+ * @param {?Error} err Request error, if any.
1090
+ * @param {Database} database The new {@link Database}.
1091
+ * @param {google.longrunning.Operation} operation An {@link Operation} object that can be used to
1092
+ * check the status of the request.
1093
+ * @param {object} apiResponse The full API response.
1094
+ */
1095
+ /**
1096
+ * Restore a backup into this database.
1097
+ *
1098
+ * When this call completes, the restore will have commenced but will not
1099
+ * necessarily have completed.
1100
+ *
1101
+ * @param {string} backupPath The path of the backup to restore.
1102
+ * @param {RestoreOptions} [options] Request configuration options.
1103
+ * @param {RestoreDatabaseCallback} [callback] Callback function.
1104
+ * @returns {Promise<RestoreDatabaseResponse>} When resolved, contains the restore operation.
1105
+ *
1106
+ * @example
1107
+ * ```
1108
+ * const {Spanner} = require('@google-cloud/spanner');
1109
+ * const spanner = new Spanner();
1110
+ * const instance = spanner.instance('my-instance');
1111
+ * const database = instance.database('my-database');
1112
+ * const backupName = 'projects/my-project/instances/my-instance/backups/my-backup';
1113
+ * const [, restoreOperation] = await database.restore(backupName);
1114
+ * // Wait for restore to complete
1115
+ * await restoreOperation.promise();
1116
+ *
1117
+ * //-
1118
+ * // Restore database with a different encryption key to the one used by the
1119
+ * // backup.
1120
+ * //-
1121
+ * const [, restoreWithKeyOperation] = await database.restore(
1122
+ * backupName,
1123
+ * {
1124
+ * encryptionConfig: {
1125
+ * encryptionType: 'CUSTOMER_MANAGED_ENCRYPTION',
1126
+ * kmsKeyName: 'projects/my-project-id/my-region/keyRings/my-key-ring/cryptoKeys/my-key',
1127
+ * }
1128
+ * },
1129
+ * );
1130
+ * // Wait for restore to complete
1131
+ * await restoreWithKeyOperation.promise();
1132
+ * ```
1133
+ */
254
1134
  restore(backupPath: string): Promise<RestoreDatabaseResponse>;
255
1135
  restore(backupPath: string, options?: RestoreOptions | CallOptions): Promise<RestoreDatabaseResponse>;
256
1136
  restore(backupPath: string, callback: RestoreDatabaseCallback): void;
257
1137
  restore(backupPath: string, options: RestoreOptions | CallOptions, callback: RestoreDatabaseCallback): void;
1138
+ /**
1139
+ * Transaction options.
1140
+ *
1141
+ * @typedef {object} DatabaseRunRequest
1142
+ * @property {number} [exactStaleness] Executes all reads at the timestamp
1143
+ * that is `exactStaleness` old.
1144
+ * @property {date} [readTimestamp] Execute all reads at the given
1145
+ * timestamp.
1146
+ * @property {boolean} [strong] Read at the timestamp where all previously
1147
+ * committed transactions are visible.
1148
+ */
1149
+ /**
1150
+ * @typedef {array} RunResponse
1151
+ * @property {Array<Row | Json>} 0 Rows are returned as an array objects. Each
1152
+ * object has a `name` and `value` property. To get a serialized object,
1153
+ * call `toJSON()`.
1154
+ * @property {?google.spanner.v1.IResultSetStats} 1 Query statistics, if the query is executed in
1155
+ * PLAN or PROFILE mode.
1156
+ */
1157
+ /**
1158
+ * @callback RunCallback
1159
+ * @param {?Error} err Request error, if any.
1160
+ * @param {Array<Row | Json>} rows Rows are returned as an array of objects.
1161
+ * Each object has a `name` and `value` property. To get a serialized
1162
+ * object, call `toJSON()`.
1163
+ * @param {?google.spanner.v1.IResultSetStats} stats Query statistics, if the query is executed
1164
+ * in PLAN or PROFILE mode.
1165
+ */
1166
+ /**
1167
+ * Execute a SQL statement on this database.
1168
+ *
1169
+ * Wrapper around {@link v1.SpannerClient#executeStreamingSql}.
1170
+ *
1171
+ * @see {@link v1.SpannerClient#executeStreamingSql}
1172
+ * @see [Query Syntax](https://cloud.google.com/spanner/docs/query-syntax)
1173
+ * @see [ExecuteSql API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.ExecuteSql)
1174
+ *
1175
+ * @param {string|ExecuteSqlRequest} query A SQL query or
1176
+ * {@link ExecuteSqlRequest} object.
1177
+ * @param {TimestampBounds} [options] Snapshot timestamp bounds.
1178
+ * @param {RunCallback} [callback] Callback function.
1179
+ * @returns {Promise<RunResponse>}
1180
+ *
1181
+ * @example
1182
+ * ```
1183
+ * const {Spanner} = require('@google-cloud/spanner');
1184
+ * const spanner = new Spanner();
1185
+ *
1186
+ * const instance = spanner.instance('my-instance');
1187
+ * const database = instance.database('my-database');
1188
+ *
1189
+ * const query = 'SELECT * FROM Singers';
1190
+ *
1191
+ * database.run(query, function(err, rows) {
1192
+ * if (err) {
1193
+ * // Error handling omitted.
1194
+ * }
1195
+ *
1196
+ * const firstRow = rows[0];
1197
+ *
1198
+ * // firstRow = [
1199
+ * // {
1200
+ * // name: 'SingerId',
1201
+ * // value: '1'
1202
+ * // },
1203
+ * // {
1204
+ * // name: 'Name',
1205
+ * // value: 'Eddie Wilson'
1206
+ * // }
1207
+ * // ]
1208
+ * });
1209
+ *
1210
+ * //-
1211
+ * // Rows are returned as an array of object arrays. Each object has a `name`
1212
+ * // and `value` property. To get a serialized object, call `toJSON()`.
1213
+ * //-
1214
+ * database.run(query, function(err, rows) {
1215
+ * if (err) {
1216
+ * // Error handling omitted.
1217
+ * }
1218
+ *
1219
+ * const firstRow = rows[0];
1220
+ *
1221
+ * // firstRow.toJSON() = {
1222
+ * // SingerId: '1',
1223
+ * // Name: 'Eddie Wilson'
1224
+ * // }
1225
+ * });
1226
+ *
1227
+ * //-
1228
+ * // Alternatively, set `query.json` to `true`, and this step will be performed
1229
+ * // automatically.
1230
+ * //-
1231
+ * database.run(query, function(err, rows) {
1232
+ * if (err) {
1233
+ * // Error handling omitted.
1234
+ * }
1235
+ *
1236
+ * const firstRow = rows[0];
1237
+ *
1238
+ * // firstRow = {
1239
+ * // SingerId: '1',
1240
+ * // Name: 'Eddie Wilson'
1241
+ * // }
1242
+ * });
1243
+ *
1244
+ * //-
1245
+ * // The SQL query string can contain parameter placeholders. A parameter
1246
+ * // placeholder consists of '@' followed by the parameter name.
1247
+ * //-
1248
+ * const query = {
1249
+ * sql: 'SELECT * FROM Singers WHERE name = @name',
1250
+ * params: {
1251
+ * name: 'Eddie Wilson'
1252
+ * }
1253
+ * };
1254
+ *
1255
+ * database.run(query, function(err, rows) {});
1256
+ *
1257
+ * //-
1258
+ * // If you need to enforce a specific param type, a types map can be provided.
1259
+ * // This is typically useful if your param value can be null.
1260
+ * //-
1261
+ * const query = {
1262
+ * sql: 'SELECT * FROM Singers WHERE name = @name AND id = @id',
1263
+ * params: {
1264
+ * id: spanner.int(8),
1265
+ * name: null
1266
+ * },
1267
+ * types: {
1268
+ * id: 'int64',
1269
+ * name: 'string'
1270
+ * }
1271
+ * };
1272
+ *
1273
+ * database.run(query, function(err, rows) {});
1274
+ *
1275
+ * //-
1276
+ * // If the callback is omitted, we'll return a Promise.
1277
+ * //-
1278
+ * database.run(query).then(function(data) {
1279
+ * const rows = data[0];
1280
+ * });
1281
+ *
1282
+ * ```
1283
+ * @example <caption>include:samples/crud.js</caption>
1284
+ * region_tag:spanner_query_data
1285
+ * Full example:
1286
+ *
1287
+ * @example <caption>include:samples/index-query-data.js</caption>
1288
+ * region_tag:spanner_query_data_with_index
1289
+ * Querying data with an index:
1290
+ */
258
1291
  run(query: string | ExecuteSqlRequest): Promise<RunResponse>;
259
1292
  run(query: string | ExecuteSqlRequest, options?: TimestampBounds): Promise<RunResponse>;
260
1293
  run(query: string | ExecuteSqlRequest, callback: RunCallback): void;
261
1294
  run(query: string | ExecuteSqlRequest, options: TimestampBounds, callback: RunCallback): void;
1295
+ /**
1296
+ * Partitioned DML transactions are used to execute DML statements with a
1297
+ * different execution strategy that provides different, and often better,
1298
+ * scalability properties for large, table-wide operations than DML in a
1299
+ * Transaction transaction. Smaller scoped statements, such as an OLTP workload,
1300
+ * should prefer using Transaction transactions.
1301
+ *
1302
+ * @see {@link Transaction#runUpdate}
1303
+ *
1304
+ * @param {string|ExecuteSqlRequest} query A DML statement or
1305
+ * {@link ExecuteSqlRequest} object.
1306
+ * @param {RunUpdateCallback} [callback] Callback function.
1307
+ * @returns {Promise<RunUpdateResponse>}
1308
+ */
262
1309
  runPartitionedUpdate(query: string | ExecuteSqlRequest): Promise<[number]>;
263
1310
  runPartitionedUpdate(query: string | ExecuteSqlRequest, callback?: RunUpdateCallback): void;
264
1311
  _runPartitionedUpdate(session: Session, query: string | ExecuteSqlRequest, callback?: RunUpdateCallback): void | Promise<number>;
@@ -280,6 +1327,7 @@ declare class Database extends common.GrpcServiceObject {
280
1327
  * @returns {PartialResultStream} A readable stream that emits rows.
281
1328
  *
282
1329
  * @example
1330
+ * ```
283
1331
  * const {Spanner} = require('@google-cloud/spanner');
284
1332
  * const spanner = new Spanner();
285
1333
  *
@@ -384,8 +1432,98 @@ declare class Database extends common.GrpcServiceObject {
384
1432
  * .on('data', function(row) {
385
1433
  * this.end();
386
1434
  * });
1435
+ * ```
387
1436
  */
388
1437
  runStream(query: string | ExecuteSqlRequest, options?: TimestampBounds): PartialResultStream;
1438
+ /**
1439
+ * @typedef {object} RunTransactionOptions
1440
+ * @property {number} [timeout] The maximum amount of time (in ms) that a
1441
+ * {@link Transaction} should be ran for.
1442
+ */
1443
+ /**
1444
+ * @callback RunTransactionCallback
1445
+ * @param {?Error} err An error returned while making this request.
1446
+ * @param {Transaction} transaction The transaction object. The transaction has
1447
+ * already been created, and is ready to be queried and committed against.
1448
+ */
1449
+ /**
1450
+ * A transaction in Cloud Spanner is a set of reads and writes that execute
1451
+ * atomically at a single logical point in time across columns, rows, and tables
1452
+ * in a database.
1453
+ *
1454
+ * Note that Cloud Spanner does not support nested transactions. If a new
1455
+ * transaction is started inside of the run function, it will be an independent
1456
+ * transaction.
1457
+ *
1458
+ * The callback you provide to this function will become the "run function". It
1459
+ * will be executed with either an error or a {@link Transaction}
1460
+ * object. The Transaction object will let you run queries and queue mutations
1461
+ * until you are ready to {@link Transaction#commit}.
1462
+ *
1463
+ * In the event that an aborted error occurs, we will re-run the `runFn` in its
1464
+ * entirety. If you prefer to handle aborted errors for yourself please refer to
1465
+ * {@link Database#getTransaction}.
1466
+ *
1467
+ * **NOTE:** In the event that you encounter an error while reading/writing,
1468
+ * if you decide to forgo calling {@link Transaction#commit} or
1469
+ * {@link Transaction#rollback}, then you need to call
1470
+ * {@link Transaction#end} to release the underlying {@link Session} object.
1471
+ * **Failure to do could result in a Session leak.**
1472
+ *
1473
+ * For a more complete listing of functionality available to a Transaction, see
1474
+ * the {@link Transaction} API documentation. For a general overview of
1475
+ * transactions within Cloud Spanner, see
1476
+ * [Transactions](https://cloud.google.com/spanner/docs/transactions) from the
1477
+ * official Cloud Spanner documentation.
1478
+ *
1479
+ * If you would like to run a transaction and receive a promise or use
1480
+ * async/await, use {@link Database#runTransactionAsync}.
1481
+ *
1482
+ * @see [Transactions](https://cloud.google.com/spanner/docs/transactions)
1483
+ *
1484
+ * @param {RunTransactionOptions} [options] Transaction runner options.
1485
+ * @param {RunTransactionCallback} callback A function to execute in the context
1486
+ * of a transaction.
1487
+ *
1488
+ * @example
1489
+ * ```
1490
+ * const {Spanner} = require('@google-cloud/spanner');
1491
+ * const spanner = new Spanner();
1492
+ *
1493
+ * const instance = spanner.instance('my-instance');
1494
+ * const database = instance.database('my-database');
1495
+ *
1496
+ * database.runTransaction(function(err, transaction) {
1497
+ * if (err) {
1498
+ * // Error handling omitted.
1499
+ * }
1500
+ *
1501
+ * // Run a transactional query.
1502
+ * transaction.run('SELECT * FROM Singers', function(err, rows) {
1503
+ * if (err) {
1504
+ * // Error handling omitted.
1505
+ * }
1506
+ *
1507
+ * // Queue a mutation (note that there is no callback passed to `insert`).
1508
+ * transaction.insert('Singers', {
1509
+ * SingerId: 'Id3b',
1510
+ * Name: 'Joe West'
1511
+ * });
1512
+ *
1513
+ * // Commit the transaction.
1514
+ * transaction.commit(function(err) {
1515
+ * if (!err) {
1516
+ * // Transaction committed successfully.
1517
+ * }
1518
+ * });
1519
+ * });
1520
+ * });
1521
+ *
1522
+ * ```
1523
+ * @example <caption>include:samples/transaction.js</caption>
1524
+ * region_tag:spanner_read_write_transaction
1525
+ * Read-write transaction:
1526
+ */
389
1527
  runTransaction(runFn: RunTransactionCallback): void;
390
1528
  runTransaction(options: RunTransactionOptions, runFn: RunTransactionCallback): void;
391
1529
  runTransactionAsync<T = {}>(runFn: AsyncRunTransactionCallback<T>): Promise<T>;
@@ -401,7 +1539,9 @@ declare class Database extends common.GrpcServiceObject {
401
1539
  * @returns {Session} A Session object.
402
1540
  *
403
1541
  * @example
1542
+ * ```
404
1543
  * var session = database.session('session-name');
1544
+ * ```
405
1545
  */
406
1546
  session(name?: string): Session;
407
1547
  /**
@@ -413,6 +1553,7 @@ declare class Database extends common.GrpcServiceObject {
413
1553
  * @return {Table} A Table object.
414
1554
  *
415
1555
  * @example
1556
+ * ```
416
1557
  * const {Spanner} = require('@google-cloud/spanner');
417
1558
  * const spanner = new Spanner();
418
1559
  *
@@ -420,8 +1561,87 @@ declare class Database extends common.GrpcServiceObject {
420
1561
  * const database = instance.database('my-database');
421
1562
  *
422
1563
  * const table = database.table('Singers');
1564
+ * ```
423
1565
  */
424
1566
  table(name: string): Table;
1567
+ /**
1568
+ * Update the schema of the database by creating/altering/dropping tables,
1569
+ * columns, indexes, etc.
1570
+ *
1571
+ * This method immediately responds with an Operation object. Register event
1572
+ * handlers for the "error" and "complete" events to see how the operation
1573
+ * finishes. Follow along with the examples below.
1574
+ *
1575
+ * Wrapper around {@link v1.DatabaseAdminClient#updateDatabaseDdl}.
1576
+ *
1577
+ * @see {@link v1.DatabaseAdminClient#updateDatabaseDdl}
1578
+ * @see [Data Definition Language (DDL)](https://cloud.google.com/spanner/docs/data-definition-language)
1579
+ * @see [Schema and Data Model](https://cloud.google.com/spanner/docs/schema-and-data-model)
1580
+ * @see [UpdateDatabaseDdl API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.UpdateDatabaseDdlRequest)
1581
+ *
1582
+ * @param {string|string[]|object} statements An array of database DDL
1583
+ * statements, or an
1584
+ * [`UpdateDatabaseDdlRequest` object](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.UpdateDatabaseDdlRequest).
1585
+ * @param {object} [gaxOptions] Request configuration options,
1586
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
1587
+ * for more details.
1588
+ * @param {LongRunningOperationCallback} [callback] Callback function.
1589
+ * @returns {Promise<LongRunningOperationResponse>}
1590
+ *
1591
+ * @example
1592
+ * ```
1593
+ * const {Spanner} = require('@google-cloud/spanner');
1594
+ * const spanner = new Spanner();
1595
+ *
1596
+ * const instance = spanner.instance('my-instance');
1597
+ * const database = instance.database('my-database');
1598
+ *
1599
+ * const statements = [
1600
+ * 'CREATE TABLE Singers (' +
1601
+ * ' SingerId INT64 NOT NULL,' +
1602
+ * ' FirstName STRING(1024),' +
1603
+ * ' LastName STRING(1024),' +
1604
+ * ' SingerInfo BYTES(MAX),' +
1605
+ * ') PRIMARY KEY(SingerId)'
1606
+ * ];
1607
+ *
1608
+ * database.updateSchema(statements, function(err, operation, apiResponse) {
1609
+ * if (err) {
1610
+ * // Error handling omitted.
1611
+ * }
1612
+ *
1613
+ * operation
1614
+ * .on('error', function(err) {})
1615
+ * .on('complete', function() {
1616
+ * // Database schema updated successfully.
1617
+ * });
1618
+ * });
1619
+ *
1620
+ * //-
1621
+ * // If the callback is omitted, we'll return a Promise.
1622
+ * //-
1623
+ * database.updateSchema(statements)
1624
+ * .then(function(data) {
1625
+ * const operation = data[0];
1626
+ * return operation.promise();
1627
+ * })
1628
+ * .then(function() {
1629
+ * // Database schema updated successfully.
1630
+ * });
1631
+ *
1632
+ * ```
1633
+ * @example <caption>include:samples/schema.js</caption>
1634
+ * region_tag:spanner_add_column
1635
+ * Adding a column:
1636
+ *
1637
+ * @example <caption>include:samples/index-create.js</caption>
1638
+ * region_tag:spanner_create_index
1639
+ * Creating an index:
1640
+ *
1641
+ * @example <caption>include:samples/index-create-stroing.js</caption>
1642
+ * region_tag:spanner_create_storing_index
1643
+ * Creating a storing index:
1644
+ */
425
1645
  updateSchema(statements: Schema, gaxOptions?: CallOptions): Promise<UpdateSchemaResponse>;
426
1646
  updateSchema(statements: Schema, callback: UpdateSchemaCallback): void;
427
1647
  updateSchema(statements: Schema, gaxOptions: CallOptions, callback: UpdateSchemaCallback): void;
@@ -435,11 +1655,13 @@ declare class Database extends common.GrpcServiceObject {
435
1655
  * @returns {string}
436
1656
  *
437
1657
  * @example
1658
+ * ```
438
1659
  * Database.formatName_(
439
1660
  * 'projects/grape-spaceship-123/instances/my-instance',
440
1661
  * 'my-database'
441
1662
  * );
442
1663
  * // 'projects/grape-spaceship-123/instances/my-instance/databases/my-database'
1664
+ * ```
443
1665
  */
444
1666
  static formatName_(instanceName: string, name: string): string;
445
1667
  }