@google-cloud/spanner 5.15.2 → 5.16.3

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.
@@ -43,10 +43,12 @@ const arrify = require("arrify");
43
43
  * The default query options to use for queries on the database.
44
44
  *
45
45
  * @example
46
+ * ```
46
47
  * const {Spanner} = require('@google-cloud/spanner');
47
48
  * const spanner = new Spanner();
48
49
  * const instance = spanner.instance('my-instance');
49
50
  * const database = instance.database('my-database');
51
+ * ```
50
52
  */
51
53
  class Database extends common.GrpcServiceObject {
52
54
  constructor(instance, name, poolOptions, queryOptions) {
@@ -60,6 +62,7 @@ class Database extends common.GrpcServiceObject {
60
62
  * @returns {Promise<CreateDatabaseResponse>}
61
63
  *
62
64
  * @example
65
+ * ```
63
66
  * const {Spanner} = require('@google-cloud/spanner');
64
67
  * const spanner = new Spanner();
65
68
  * const instance = spanner.instance('my-instance');
@@ -90,6 +93,7 @@ class Database extends common.GrpcServiceObject {
90
93
  * .then(function() {
91
94
  * // Database created successfully.
92
95
  * });
96
+ * ```
93
97
  */
94
98
  create: true,
95
99
  };
@@ -160,64 +164,6 @@ class Database extends common.GrpcServiceObject {
160
164
  }
161
165
  return options;
162
166
  }
163
- /**
164
- * @typedef {object} BatchCreateSessionsOptions
165
- * @property {number} count The number of sessions to create.
166
- * @property {object.<string, string>} [labels] Labels to apply to each
167
- * session.
168
- * @property {object} [gaxOptions] Request configuration options,
169
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
170
- * for more details.
171
- */
172
- /**
173
- * @typedef {array} BatchCreateSessionsResponse
174
- * @property {Session[]} 0 The newly created sessions.
175
- * @property {object} 1 The full API response.
176
- */
177
- /**
178
- * @callback BatchCreateSessionsCallback
179
- * @param {?Error} err Request error, if any.
180
- * @param {Session[]} sessions The newly created sessions.
181
- * @param {object} apiResponse The full API response.
182
- */
183
- /**
184
- * Create a batch of sessions, which can be used to perform transactions that
185
- * read and/or modify data.
186
- *
187
- * **It is unlikely you will need to interact with sessions directly. By
188
- * default, sessions are created and utilized for maximum performance
189
- * automatically.**
190
- *
191
- * Wrapper around {@link v1.SpannerClient#batchCreateSessions}.
192
- *
193
- * @see {@link v1.SpannerClient#batchCreateSessions}
194
- * @see [BatchCreateSessions API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.BatchCreateSessions)
195
- *
196
- * @param {number|BatchCreateSessionsOptions} options Desired session count or
197
- * a configuration object.
198
- * @param {BatchCreateSessionsCallback} [callback] Callback function.
199
- * @returns {Promise<BatchCreateSessionsResponse>}
200
- *
201
- * @example
202
- * const {Spanner} = require('@google-cloud/spanner');
203
- * const spanner = new Spanner();
204
- *
205
- * const instance = spanner.instance('my-instance');
206
- * const database = instance.database('my-database');
207
- *
208
- * const count = 5;
209
- *
210
- * database.batchCreateSession(count, (err, sessions, response) => {
211
- * if (err) {
212
- * // Error handling omitted.
213
- * }
214
- *
215
- * // `sessions` is an array of Session objects.
216
- * });
217
- *
218
- * @example <caption>If the callback is omitted, we'll return a Promise.</caption>
219
- * const [sessions, response] = await database.batchCreateSessions(count);
220
- */
221
167
  batchCreateSessions(options, callback) {
222
168
  if (typeof options === 'number') {
223
169
  options = { count: options };
@@ -258,6 +204,7 @@ class Database extends common.GrpcServiceObject {
258
204
  * @returns {BatchTransaction} A batch transaction object.
259
205
  *
260
206
  * @example
207
+ * ```
261
208
  * const {Spanner} = require('@google-cloud/spanner');
262
209
  * const spanner = new Spanner();
263
210
  *
@@ -269,6 +216,7 @@ class Database extends common.GrpcServiceObject {
269
216
  * transaction: 'my-transaction',
270
217
  * readTimestamp: 1518464696657
271
218
  * });
219
+ * ```
272
220
  */
273
221
  batchTransaction(identifier, options) {
274
222
  const session = typeof identifier.session === 'string'
@@ -280,65 +228,12 @@ class Database extends common.GrpcServiceObject {
280
228
  transaction.readTimestamp = identifier.timestamp;
281
229
  return transaction;
282
230
  }
283
- /**
284
- * @callback CloseDatabaseCallback
285
- * @param {?Error} err Request error, if any.
286
- */
287
- /**
288
- * Close the database connection and destroy all sessions associated with it.
289
- *
290
- * @param {CloseDatabaseCallback} [callback] Callback function.
291
- * @returns {Promise}
292
- *
293
- * @example
294
- * const {Spanner} = require('@google-cloud/spanner');
295
- * const spanner = new Spanner();
296
- *
297
- * const instance = spanner.instance('my-instance');
298
- * const database = instance.database('my-database');
299
- *
300
- * database.close(function(err) {
301
- * if (err) {
302
- * // Error handling omitted.
303
- * }
304
- * });
305
- *
306
- * //-
307
- * // In the event of a session leak, the error object will contain a
308
- * // `messages` field.
309
- * //-
310
- * database.close(function(err) {
311
- * if (err && err.messages) {
312
- * err.messages.forEach(function(message) {
313
- * console.error(message);
314
- * });
315
- * }
316
- * });
317
- */
318
231
  close(callback) {
319
232
  const key = this.id.split('/').pop();
320
233
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
321
234
  this.parent.databases_.delete(key);
322
235
  this.pool_.close(callback);
323
236
  }
324
- /**
325
- * @typedef {array} CreateTransactionResponse
326
- * @property {BatchTransaction} 0 The {@link BatchTransaction}.
327
- * @property {object} 1 The full API response.
328
- */
329
- /**
330
- * @callback CreateTransactionCallback
331
- * @param {?Error} err Request error, if any.
332
- * @param {BatchTransaction} transaction The {@link BatchTransaction}.
333
- * @param {object} apiResponse The full API response.
334
- */
335
- /**
336
- * Create a transaction that can be used for batch querying.
337
- *
338
- * @param {object} [options] [Transaction options](https://cloud.google.com/spanner/docs/timestamp-bounds).
339
- * @param {CreateTransactionCallback} [callback] Callback function.
340
- * @returns {Promise<CreateTransactionResponse>}
341
- */
342
237
  createBatchTransaction(optionsOrCallback, cb) {
343
238
  const callback = typeof optionsOrCallback === 'function'
344
239
  ? optionsOrCallback
@@ -362,77 +257,6 @@ class Database extends common.GrpcServiceObject {
362
257
  });
363
258
  });
364
259
  }
365
- /**
366
- * Create a new session.
367
- *
368
- * @typedef {object} CreateSessionOptions
369
- * @property {Object.<string, string>} [labels] The labels for the session.
370
- *
371
- * * Label keys must be between 1 and 63 characters long and must conform to
372
- * the following regular expression: `[a-z]([-a-z0-9]*[a-z0-9])?`.
373
- * * Label values must be between 0 and 63 characters long and must conform
374
- * to the regular expression `([a-z]([-a-z0-9]*[a-z0-9])?)?`.
375
- * * No more than 64 labels can be associated with a given session.
376
- * @property {object} [gaxOptions] Request configuration options,
377
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
378
- * for more details.
379
- */
380
- /**
381
- * @typedef {array} CreateSessionResponse
382
- * @property {Session} 0 The newly created session.
383
- * @property {object} 1 The full API response.
384
- */
385
- /**
386
- * @callback CreateSessionCallback
387
- * @param {?Error} err Request error, if any.
388
- * @param {Session} session The newly created session.
389
- * @param {object} apiResponse The full API response.
390
- */
391
- /**
392
- * Create a new session, which can be used to perform transactions that read
393
- * and/or modify data.
394
- *
395
- * Sessions can only execute one transaction at a time. To execute multiple
396
- * concurrent read-write/write-only transactions, create multiple sessions.
397
- * Note that standalone reads and queries use a transaction internally, and
398
- * count toward the one transaction limit.
399
- *
400
- * **It is unlikely you will need to interact with sessions directly. By
401
- * default, sessions are created and utilized for maximum performance
402
- * automatically.**
403
- *
404
- * Wrapper around {@link v1.SpannerClient#createSession}.
405
- *
406
- * @see {@link v1.SpannerClient#createSession}
407
- * @see [CreateSession API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.CreateSession)
408
- *
409
- * @param {CreateSessionOptions} [options] Configuration object.
410
- * @param {CreateSessionCallback} [callback] Callback function.
411
- * @returns {Promise<CreateSessionResponse>}
412
- *
413
- * @example
414
- * const {Spanner} = require('@google-cloud/spanner');
415
- * const spanner = new Spanner();
416
- *
417
- * const instance = spanner.instance('my-instance');
418
- * const database = instance.database('my-database');
419
- *
420
- * database.createSession(function(err, session, apiResponse) {
421
- * if (err) {
422
- * // Error handling omitted.
423
- * }
424
- *
425
- * // `session` is a Session object.
426
- * });
427
- *
428
- * //-
429
- * // If the callback is omitted, we'll return a Promise.
430
- * //-
431
- * database.createSession().then(function(data) {
432
- * const session = data[0];
433
- * const apiResponse = data[1];
434
- * });
435
- */
436
260
  createSession(optionsOrCallback, cb) {
437
261
  const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
438
262
  const options = typeof optionsOrCallback === 'object' && optionsOrCallback
@@ -460,76 +284,6 @@ class Database extends common.GrpcServiceObject {
460
284
  callback(null, session, resp);
461
285
  });
462
286
  }
463
- /**
464
- * @typedef {array} CreateTableResponse
465
- * @property {Table} 0 The new {@link Table}.
466
- * @property {google.longrunning.Operation} 1 An {@link Operation} object that can be used to check
467
- * the status of the request.
468
- * @property {object} 2 The full API response.
469
- */
470
- /**
471
- * @callback CreateTableCallback
472
- * @param {?Error} err Request error, if any.
473
- * @param {Table} table The new {@link Table}.
474
- * @param {google.longrunning.Operation} operation An {@link Operation} object that can be used to
475
- * check the status of the request.
476
- * @param {object} apiResponse The full API response.
477
- */
478
- /**
479
- * Create a table.
480
- *
481
- * Wrapper around {@link Database#updateSchema}.
482
- *
483
- * @see {@link Database#updateSchema}
484
- *
485
- * @param {string} schema A DDL CREATE statement describing the table.
486
- * @param {object} [gaxOptions] Request configuration options,
487
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
488
- * for more details.
489
- * @param {CreateTableCallback} [callback] Callback function.
490
- * @returns {Promise<CreateTableResponse>}
491
- *
492
- * @example
493
- * const {Spanner} = require('@google-cloud/spanner');
494
- * const spanner = new Spanner();
495
- *
496
- * const instance = spanner.instance('my-instance');
497
- * const database = instance.database('my-database');
498
- *
499
- * const schema =
500
- * 'CREATE TABLE Singers (' +
501
- * ' SingerId INT64 NOT NULL,' +
502
- * ' FirstName STRING(1024),' +
503
- * ' LastName STRING(1024),' +
504
- * ' SingerInfo BYTES(MAX),' +
505
- * ') PRIMARY KEY(SingerId)';
506
- *
507
- * database.createTable(schema, function(err, table, operation, apiResponse) {
508
- * if (err) {
509
- * // Error handling omitted.
510
- * }
511
- *
512
- * operation
513
- * .on('error', function(err) {})
514
- * .on('complete', function() {
515
- * // Table created successfully.
516
- * });
517
- * });
518
- *
519
- * //-
520
- * // If the callback is omitted, we'll return a Promise.
521
- * //-
522
- * database.createTable(schema)
523
- * .then(function(data) {
524
- * const table = data[0];
525
- * const operation = data[1];
526
- *
527
- * return operation.promise();
528
- * })
529
- * .then(function() {
530
- * // Table created successfully.
531
- * });
532
- */
533
287
  createTable(schema, gaxOptionsOrCallback, cb) {
534
288
  const gaxOptions = typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
535
289
  const callback = typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb;
@@ -563,51 +317,6 @@ class Database extends common.GrpcServiceObject {
563
317
  }
564
318
  });
565
319
  }
566
- /**
567
- * @typedef {array} DatabaseDeleteResponse
568
- * @property {object} 0 The full API response.
569
- */
570
- /**
571
- * @callback DatabaseDeleteCallback
572
- * @param {?Error} err Request error, if any.
573
- * @param {object} apiResponse The full API response.
574
- */
575
- /**
576
- * Delete the database.
577
- *
578
- * Wrapper around {@link v1.DatabaseAdminClient#dropDatabase}.
579
- *
580
- * @see {@link v1.DatabaseAdminClient#dropDatabase}
581
- * @see [DropDatabase API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.DatabaseAdmin.DropDatabase)
582
- *
583
- * @param {object} [gaxOptions] Request configuration options,
584
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
585
- * for more details.
586
- * @param {DatabaseDeleteCallback} [callback] Callback function.
587
- * @returns {Promise<DatabaseDeleteResponse>}
588
- *
589
- * @example
590
- * const {Spanner} = require('@google-cloud/spanner');
591
- * const spanner = new Spanner();
592
- *
593
- * const instance = spanner.instance('my-instance');
594
- * const database = instance.database('my-database');
595
- *
596
- * database.delete(function(err, apiResponse) {
597
- * if (err) {
598
- * // Error handling omitted.
599
- * }
600
- *
601
- * // Database was deleted successfully.
602
- * });
603
- *
604
- * //-
605
- * // If the callback is omitted, we'll return a Promise.
606
- * //-
607
- * database.delete().then(function(data) {
608
- * const apiResponse = data[0];
609
- * });
610
- */
611
320
  delete(optionsOrCallback, cb) {
612
321
  const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
613
322
  const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
@@ -624,41 +333,6 @@ class Database extends common.GrpcServiceObject {
624
333
  }, callback);
625
334
  });
626
335
  }
627
- /**
628
- * @typedef {array} DatabaseExistsResponse
629
- * @property {boolean} 0 Whether the {@link Database} exists.
630
- */
631
- /**
632
- * @callback DatabaseExistsCallback
633
- * @param {?Error} err Request error, if any.
634
- * @param {boolean} exists Whether the {@link Database} exists.
635
- */
636
- /**
637
- * Check if a database exists.
638
- *
639
- * @method Database#exists
640
- * @param {object} [gaxOptions] Request configuration options,
641
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
642
- * for more details.
643
- * @param {DatabaseExistsCallback} [callback] Callback function.
644
- * @returns {Promise<DatabaseExistsResponse>}
645
- *
646
- * @example
647
- * const {Spanner} = require('@google-cloud/spanner');
648
- * const spanner = new Spanner();
649
- *
650
- * const instance = spanner.instance('my-instance');
651
- * const database = instance.database('my-database');
652
- *
653
- * database.exists(function(err, exists) {});
654
- *
655
- * //-
656
- * // If the callback is omitted, we'll return a Promise.
657
- * //-
658
- * database.exists().then(function(data) {
659
- * const exists = data[0];
660
- * });
661
- */
662
336
  exists(gaxOptionsOrCallback, cb) {
663
337
  const gaxOptions = typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
664
338
  const callback = typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb;
@@ -672,53 +346,6 @@ class Database extends common.GrpcServiceObject {
672
346
  callback(null, exists);
673
347
  });
674
348
  }
675
- /**
676
- * @typedef {array} GetDatabaseResponse
677
- * @property {Database} 0 The {@link Database}.
678
- * @property {object} 1 The full API response.
679
- */
680
- /**
681
- * @callback GetDatabaseCallback
682
- * @param {?Error} err Request error, if any.
683
- * @param {Database} database The {@link Database}.
684
- * @param {object} apiResponse The full API response.
685
- */
686
- /**
687
- * Get a database if it exists.
688
- *
689
- * You may optionally use this to "get or create" an object by providing an
690
- * object with `autoCreate` set to `true`. Any extra configuration that is
691
- * normally required for the `create` method must be contained within this
692
- * object as well.
693
- *
694
- * @param {options} [options] Configuration object.
695
- * @param {boolean} [options.autoCreate=false] Automatically create the
696
- * object if it does not exist.
697
- * @param {object} [options.gaxOptions] Request configuration options,
698
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
699
- * for more details.
700
- * @param {GetDatabaseCallback} [callback] Callback function.
701
- * @returns {Promise<GetDatabaseResponse>}
702
- *
703
- * @example
704
- * const {Spanner} = require('@google-cloud/spanner');
705
- * const spanner = new Spanner();
706
- *
707
- * const instance = spanner.instance('my-instance');
708
- * const database = instance.database('my-database');
709
- *
710
- * database.get(function(err, database, apiResponse) {
711
- * // `database.metadata` has been populated.
712
- * });
713
- *
714
- * //-
715
- * // If the callback is omitted, we'll return a Promise.
716
- * //-
717
- * database.get().then(function(data) {
718
- * const database = data[0];
719
- * const apiResponse = data[0];
720
- * });
721
- */
722
349
  get(optionsOrCallback, cb) {
723
350
  const options = typeof optionsOrCallback === 'object'
724
351
  ? optionsOrCallback
@@ -747,53 +374,6 @@ class Database extends common.GrpcServiceObject {
747
374
  callback(null, this, metadata);
748
375
  });
749
376
  }
750
- /**
751
- * @typedef {array} GetDatabaseMetadataResponse
752
- * @property {object} 0 The {@link Database} metadata.
753
- * @property {object} 1 The full API response.
754
- */
755
- /**
756
- * @callback GetDatabaseMetadataCallback
757
- * @param {?Error} err Request error, if any.
758
- * @param {object} metadata The {@link Database} metadata.
759
- * @param {object} apiResponse The full API response.
760
- */
761
- /**
762
- * Get the database's metadata.
763
- *
764
- * Wrapper around {@link v1.DatabaseAdminClient#getDatabase}.
765
- *
766
- * @see {@link v1.DatabaseAdminClient#getDatabase}
767
- * @see [GetDatabase API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.DatabaseAdmin.GetDatabase)
768
- * @param {object} [gaxOptions] Request configuration options,
769
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
770
- * for more details.
771
- * @param {GetDatabaseMetadataCallback} [callback] Callback function.
772
- * @returns {Promise<GetDatabaseMetadataResponse>}
773
- *
774
- * @example
775
- * const {Spanner} = require('@google-cloud/spanner');
776
- * const spanner = new Spanner();
777
- *
778
- * const instance = spanner.instance('my-instance');
779
- * const database = instance.database('my-database');
780
- *
781
- * database.getMetadata(function(err, metadata) {
782
- * if (err) {
783
- * // Error handling omitted.
784
- * }
785
- *
786
- * // Database was deleted successfully.
787
- * });
788
- *
789
- * //-
790
- * // If the callback is omitted, we'll return a Promise.
791
- * //-
792
- * database.getMetadata().then(function(data) {
793
- * const metadata = data[0];
794
- * const apiResponse = data[1];
795
- * });
796
- */
797
377
  getMetadata(gaxOptionsOrCallback, cb) {
798
378
  const callback = typeof gaxOptionsOrCallback === 'function'
799
379
  ? gaxOptionsOrCallback
@@ -817,124 +397,16 @@ class Database extends common.GrpcServiceObject {
817
397
  callback(err, resp);
818
398
  });
819
399
  }
820
- /**
821
- * {@link google.spanner.admin.database.v1#RestoreInfo} structure with restore
822
- * source type enum translated to string form.
823
- *
824
- * @typedef {object} IRestoreInfoTranslatedEnum
825
- */
826
- /**
827
- * @callback GetRestoreInfoCallback
828
- * @param {?Error} err Request error, if any.
829
- * @param {IRestoreInfoTranslatedEnum | undefined} restoreInfo Contains the restore
830
- * information for the database if it was restored from a backup.
831
- */
832
- /**
833
- * Retrieves the restore information of the database.
834
- *
835
- * @see {@link #getMetadata}
836
- *
837
- * @method Database#getRestoreInfo
838
- * @param {object} [gaxOptions] Request configuration options,
839
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
840
- * for more details.
841
- * @param {GetRestoreInfoCallback} [callback] Callback function.
842
- * @returns {Promise<IRestoreInfoTranslatedEnum | undefined>} When resolved,
843
- * contains the restore information for the database if it was restored
844
- * from a backup.
845
- *
846
- * @example
847
- * const {Spanner} = require('@google-cloud/spanner');
848
- * const spanner = new Spanner();
849
- * const instance = spanner.instance('my-instance');
850
- * const database = instance.database('my-database');
851
- * const restoreInfo = await database.getRestoreInfo();
852
- * console.log(`Database restored from ${restoreInfo.backupInfo.backup}`);
853
- */
854
400
  async getRestoreInfo(optionsOrCallback) {
855
401
  const gaxOptions = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
856
402
  const [metadata] = await this.getMetadata(gaxOptions);
857
403
  return metadata.restoreInfo ? metadata.restoreInfo : undefined;
858
404
  }
859
- /**
860
- * @callback GetStateCallback
861
- * @param {?Error} err Request error, if any.
862
- * @param {EnumKey<typeof, google.spanner.admin.database.v1.Database.State> | undefined} state
863
- * Contains the current state of the database if the state is defined.
864
- */
865
- /**
866
- * Retrieves the state of the database.
867
- *
868
- * The database state indicates if the database is ready after creation or
869
- * after being restored from a backup.
870
- *
871
- * @see {@link #getMetadata}
872
- *
873
- * @method Database#getState
874
- * @param {object} [gaxOptions] Request configuration options,
875
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
876
- * for more details.
877
- * @param {GetStateCallback} [callback] Callback function.
878
- * @returns {Promise<EnumKey<typeof, google.spanner.admin.database.v1.Database.State> | undefined>}
879
- * When resolved, contains the current state of the database if the state
880
- * is defined.
881
- *
882
- * @example
883
- * const {Spanner} = require('@google-cloud/spanner');
884
- * const spanner = new Spanner();
885
- * const instance = spanner.instance('my-instance');
886
- * const database = instance.database('my-database');
887
- * const state = await database.getState();
888
- * const isReady = (state === 'READY');
889
- */
890
405
  async getState(optionsOrCallback) {
891
406
  const gaxOptions = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
892
407
  const [metadata] = await this.getMetadata(gaxOptions);
893
408
  return metadata.state || undefined;
894
409
  }
895
- /**
896
- * @typedef {array} GetSchemaResponse
897
- * @property {string[]} 0 An array of database DDL statements.
898
- * @property {object} 1 The full API response.
899
- */
900
- /**
901
- * @callback GetSchemaCallback
902
- * @param {?Error} err Request error, if any.
903
- * @param {string[]} statements An array of database DDL statements.
904
- * @param {object} apiResponse The full API response.
905
- */
906
- /**
907
- * Get this database's schema as a list of formatted DDL statements.
908
- *
909
- * Wrapper around {@link v1.DatabaseAdminClient#getDatabaseDdl}.
910
- *
911
- * @see {@link v1.DatabaseAdminClient#getDatabaseDdl}
912
- * @see [Data Definition Language (DDL)](https://cloud.google.com/spanner/docs/data-definition-language)
913
- * @see [GetDatabaseDdl API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.DatabaseAdmin.GetDatabaseDdl)
914
- *
915
- * @param {object} [gaxOptions] Request configuration options,
916
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
917
- * for more details.
918
- * @param {GetSchemaCallback} [callback] Callback function.
919
- * @returns {Promise<GetSchemaResponse>}
920
- *
921
- * @example
922
- * const {Spanner} = require('@google-cloud/spanner');
923
- * const spanner = new Spanner();
924
- *
925
- * const instance = spanner.instance('my-instance');
926
- * const database = instance.database('my-database');
927
- *
928
- * database.getSchema(function(err, statements, apiResponse) {});
929
- *
930
- * //-
931
- * // If the callback is omitted, we'll return a Promise.
932
- * //-
933
- * database.getSchema().then(function(data) {
934
- * const statements = data[0];
935
- * const apiResponse = data[1];
936
- * });
937
- */
938
410
  getSchema(optionsOrCallback, cb) {
939
411
  const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
940
412
  const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
@@ -953,89 +425,6 @@ class Database extends common.GrpcServiceObject {
953
425
  callback(err, statements ? statements.statements : null, ...args);
954
426
  });
955
427
  }
956
- /**
957
- * Options object for listing sessions.
958
- *
959
- * @typedef {object} GetSessionsOptions
960
- * @property {string} [filter] An expression for filtering the results of the
961
- * request. Filter rules are case insensitive. The fields eligible for
962
- * filtering are:
963
- * - **`name`**
964
- * - **`display_name`**
965
- * - **`labels.key`** where key is the name of a label
966
- *
967
- * Some examples of using filters are:
968
- * - **`name:*`** The instance has a name.
969
- * - **`name:Howl`** The instance's name is howl.
970
- * - **`labels.env:*`** The instance has the label env.
971
- * - **`labels.env:dev`** The instance's label env has the value dev.
972
- * - **`name:howl labels.env:dev`** The instance's name is howl and it has
973
- * the label env with value dev.
974
- * @property {number} [pageSize] Maximum number of results per page.
975
- * @property {string} [pageToken] A previously-returned page token
976
- * representing part of the larger set of results to view.
977
- * @property {object} [gaxOptions] Request configuration options,
978
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
979
- * for more details.
980
- */
981
- /**
982
- * @typedef {array} GetSessionsResponse
983
- * @property {Session[]} 0 Array of {@link Session} instances.
984
- * @property {object} 1 A query object to receive more results.
985
- * @property {object} 2 The full API response.
986
- */
987
- /**
988
- * @callback GetSessionsCallback
989
- * @param {?Error} err Request error, if any.
990
- * @param {Session[]} instances Array of {@link Session} instances.
991
- * @param {object} nextQuery A query object to receive more results.
992
- * @param {object} apiResponse The full API response.
993
- */
994
- /**
995
- * Gets a list of sessions.
996
- *
997
- * Wrapper around {@link v1.SpannerClient#listSessions}
998
- *
999
- * @see {@link v1.SpannerClient#listSessions}
1000
- * @see [ListSessions API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.ListSessions)
1001
- *
1002
- * @param {GetSessionsOptions} [options] Options object for listing sessions.
1003
- * @param {GetSessionsCallback} [callback] Callback function.
1004
- * @returns {Promise<GetSessionsResponse>}
1005
- *
1006
- * @example
1007
- * const {Spanner} = require('@google-cloud/spanner');
1008
- * const spanner = new Spanner();
1009
- *
1010
- * const instance = spanner.instance('my-instance');
1011
- * const database = instance.database('my-database');
1012
- *
1013
- * database.getSessions(function(err, sessions) {
1014
- * // `sessions` is an array of `Session` objects.
1015
- * });
1016
- *
1017
- * //-
1018
- * // To control how many API requests are made and page through the results
1019
- * // manually, set `autoPaginate` to `false`.
1020
- * //-
1021
- * function callback(err, sessions, nextQuery, apiResponse) {
1022
- * if (nextQuery) {
1023
- * // More results exist.
1024
- * database.getSessions(nextQuery, callback);
1025
- * }
1026
- * }
1027
- *
1028
- * database.getInstances({
1029
- * gaxOptions: {autoPaginate: false}
1030
- * }, callback);
1031
- *
1032
- * //-
1033
- * // If the callback is omitted, we'll return a Promise.
1034
- * //-
1035
- * database.getInstances().then(function(data) {
1036
- * const sessions = data[0];
1037
- * });
1038
- */
1039
428
  getSessions(optionsOrCallback, cb) {
1040
429
  // eslint-disable-next-line @typescript-eslint/no-this-alias
1041
430
  const self = this;
@@ -1093,6 +482,7 @@ class Database extends common.GrpcServiceObject {
1093
482
  * instances.
1094
483
  *
1095
484
  * @example
485
+ * ```
1096
486
  * const {Spanner} = require('@google-cloud/spanner');
1097
487
  * const spanner = new Spanner();
1098
488
  *
@@ -1116,6 +506,7 @@ class Database extends common.GrpcServiceObject {
1116
506
  * .on('data', function(session) {
1117
507
  * this.end();
1118
508
  * });
509
+ * ```
1119
510
  */
1120
511
  getSessionsStream(options = {}) {
1121
512
  const gaxOpts = extend(true, {}, options.gaxOptions);
@@ -1123,80 +514,24 @@ class Database extends common.GrpcServiceObject {
1123
514
  database: this.formattedName_,
1124
515
  });
1125
516
  delete reqOpts.gaxOptions;
1126
- // Copy over pageSize and pageToken values from gaxOptions.
1127
- // However values set on options take precedence.
1128
- if (gaxOpts) {
1129
- reqOpts = extend({}, {
1130
- pageSize: gaxOpts.pageSize,
1131
- pageToken: gaxOpts.pageToken,
1132
- }, reqOpts);
1133
- delete gaxOpts.pageSize;
1134
- delete gaxOpts.pageToken;
1135
- }
1136
- return this.requestStream({
1137
- client: 'SpannerClient',
1138
- method: 'listSessionsStream',
1139
- reqOpts,
1140
- gaxOpts,
1141
- headers: this.resourceHeader_,
1142
- });
1143
- }
1144
- /**
1145
- * @typedef {array} GetSnapshotResponse
1146
- * @property {Snapshot} 0 The snapshot object.
1147
- */
1148
- /**
1149
- * @callback GetSnapshotCallback
1150
- * @param {?Error} err Request error, if any.
1151
- * @param {Snapshot} snapshot The snapshot object.
1152
- */
1153
- /**
1154
- * Get a read only {@link Snapshot} transaction.
1155
- *
1156
- * Wrapper around {@link v1.SpannerClient#beginTransaction}.
1157
- *
1158
- * **NOTE:** When finished with the Snapshot, {@link Snapshot#end} should be
1159
- * called to release the underlying {@link Session}. **Failure to do could
1160
- * result in a Session leak.**
1161
- *
1162
- * **NOTE:** Since the returned {@link Snapshot} transaction is not a
1163
- * single-use transaction, it is invalid to set the `minReadTimestamp` and
1164
- * `maxStaleness` parameters in {@link TimestampBounds} as those parameters
1165
- * can only be set for single-use transactions.
1166
- * https://cloud.google.com/spanner/docs/reference/rest/v1/TransactionOptions#bounded-staleness
1167
- *
1168
- * @see {@link v1.SpannerClient#beginTransaction}
1169
- *
1170
- * @param {TimestampBounds} [options] Timestamp bounds.
1171
- * @param {GetSnapshotCallback} [callback] Callback function.
1172
- * @returns {Promise<GetSnapshotResponse>}
1173
- *
1174
- * @example
1175
- * const {Spanner} = require('@google-cloud/spanner');
1176
- * const spanner = new Spanner();
1177
- *
1178
- * const instance = spanner.instance('my-instance');
1179
- * const database = instance.database('my-database');
1180
- *
1181
- * database.getSnapshot(function(err, transaction) {
1182
- * if (err) {
1183
- * // Error handling omitted.
1184
- * }
1185
- *
1186
- * // Should be called when finished with Snapshot.
1187
- * transaction.end();
1188
- * });
1189
- *
1190
- * @example <caption>If the callback is omitted, we'll return a Promise.
1191
- * </caption>
1192
- * database.getSnapshot().then(function(data) {
1193
- * const transaction = data[0];
1194
- * });
1195
- *
1196
- * @example <caption>include:samples/transaction.js</caption>
1197
- * region_tag:spanner_read_only_transaction
1198
- * Read-only transaction:
1199
- */
517
+ // Copy over pageSize and pageToken values from gaxOptions.
518
+ // However values set on options take precedence.
519
+ if (gaxOpts) {
520
+ reqOpts = extend({}, {
521
+ pageSize: gaxOpts.pageSize,
522
+ pageToken: gaxOpts.pageToken,
523
+ }, reqOpts);
524
+ delete gaxOpts.pageSize;
525
+ delete gaxOpts.pageToken;
526
+ }
527
+ return this.requestStream({
528
+ client: 'SpannerClient',
529
+ method: 'listSessionsStream',
530
+ reqOpts,
531
+ gaxOpts,
532
+ headers: this.resourceHeader_,
533
+ });
534
+ }
1200
535
  getSnapshot(optionsOrCallback, cb) {
1201
536
  const callback = typeof optionsOrCallback === 'function'
1202
537
  ? optionsOrCallback
@@ -1228,46 +563,6 @@ class Database extends common.GrpcServiceObject {
1228
563
  });
1229
564
  });
1230
565
  }
1231
- /**
1232
- * @typedef {array} GetTransactionResponse
1233
- * @property {Transaction} 0 The transaction object.
1234
- */
1235
- /**
1236
- * @callback GetTransactionCallback
1237
- * @param {?Error} err Request error, if any.
1238
- * @param {Transaction} transaction The transaction object.
1239
- */
1240
- /**
1241
- * Get a read/write ready {@link Transaction} object.
1242
- *
1243
- * **NOTE:** In the event that you encounter an error while reading/writing,
1244
- * if you decide to forgo calling {@link Transaction#commit} or
1245
- * {@link Transaction#rollback}, then you need to call
1246
- * {@link Transaction#end} to release the underlying {@link Session} object.
1247
- * **Failure to do could result in a Session leak.**
1248
- *
1249
- * Wrapper around {@link v1.SpannerClient#beginTransaction}.
1250
- *
1251
- * @see {@link v1.SpannerClient#beginTransaction}
1252
- *
1253
- * @param {GetTransactionCallback} [callback] Callback function.
1254
- * @returns {Promise<GetTransactionResponse>}
1255
- *
1256
- * @example
1257
- * const {Spanner} = require('@google-cloud/spanner');
1258
- * const spanner = new Spanner();
1259
- *
1260
- * const instance = spanner.instance('my-instance');
1261
- * const database = instance.database('my-database');
1262
- *
1263
- * database.getTransaction(function(err, transaction) {});
1264
- *
1265
- * @example <caption>If the callback is omitted, we'll return a Promise.
1266
- * </caption>
1267
- * database.getTransaction().then(function(data) {
1268
- * const transaction = data[0];
1269
- * });
1270
- */
1271
566
  getTransaction(callback) {
1272
567
  this.pool_.getWriteSession((err, session, transaction) => {
1273
568
  if (!err) {
@@ -1276,61 +571,6 @@ class Database extends common.GrpcServiceObject {
1276
571
  callback(err, transaction);
1277
572
  });
1278
573
  }
1279
- /**
1280
- * Query object for listing database operations.
1281
- *
1282
- * @typedef {object} GetDatabaseOperationsOptions
1283
- * @property {string} [filter] An expression for filtering the results of the
1284
- * request. Filter can be configured as outlined in
1285
- * {@link v1.DatabaseAdminClient#listDatabaseOperations}.
1286
- * @property {number} [pageSize] Maximum number of results per page.
1287
- * @property {string} [pageToken] A previously-returned page token
1288
- * representing part of the larger set of results to view.
1289
- * @property {object} [gaxOptions] Request configuration options,
1290
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
1291
- * for more details.
1292
- * @param {GetDatabaseOperationsCallback} [callback] Callback function.
1293
- */
1294
- /**
1295
- * @typedef {array} GetDatabaseOperationsResponse
1296
- * @property {IOperation[]} 0 Array of {@link IOperation} instances.
1297
- * @property {object} 1 The full API response.
1298
- */
1299
- /**
1300
- * List pending and completed operations for the database.
1301
- *
1302
- * @see {@link Instance.getDatabaseOperations}
1303
- *
1304
- * @param {GetDatabaseOperationsOptions} [options] Contains query object for
1305
- * listing database operations and request configuration options,
1306
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
1307
- * for more details.
1308
- * @returns {Promise<GetDatabaseOperationsResponse>} When resolved, contains
1309
- * a paged list of database operations.
1310
- *
1311
- * @example
1312
- * const {Spanner} = require('@google-cloud/spanner');
1313
- * const spanner = new Spanner();
1314
- * const instance = spanner.instance('my-instance');
1315
- * const database = instance.database('my-database');
1316
- * const [operations] = await database.getOperations();
1317
- *
1318
- * //-
1319
- * // To manually handle pagination, set autoPaginate:false in gaxOptions.
1320
- * //-
1321
- * let pageToken = undefined;
1322
- * do {
1323
- * const [operations, , response] = await database.getOperations({
1324
- * pageSize: 3,
1325
- * pageToken,
1326
- * gaxOptions: {autoPaginate: false},
1327
- * });
1328
- * operations.forEach(operation => {
1329
- * // Do something with operation
1330
- * });
1331
- * pageToken = response.nextPageToken;
1332
- * } while (pageToken);
1333
- */
1334
574
  async getOperations(optionsOrCallback) {
1335
575
  const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
1336
576
  // Create a query that lists database operations only on this database from
@@ -1346,14 +586,6 @@ class Database extends common.GrpcServiceObject {
1346
586
  };
1347
587
  return this.instance.getDatabaseOperations(dbSpecificQuery);
1348
588
  }
1349
- /**
1350
- * Make an API request, first assuring an active session is used.
1351
- *
1352
- * @private
1353
- *
1354
- * @param {object} config Request config
1355
- * @param {function} callback Callback function
1356
- */
1357
589
  makePooledRequest_(config, callback) {
1358
590
  const pool = this.pool_;
1359
591
  pool.getReadSession((err, session) => {
@@ -1417,68 +649,6 @@ class Database extends common.GrpcServiceObject {
1417
649
  });
1418
650
  return waitForSessionStream;
1419
651
  }
1420
- /**
1421
- * @typedef {object} RestoreOptions
1422
- * @property {google.spanner.admin.database.v1.IRestoreDatabaseEncryptionConfig}
1423
- * encryptionConfig An encryption configuration describing
1424
- * the encryption type and key resources in Cloud KMS used to
1425
- * encrypt/decrypt the database to restore to.
1426
- * @property {CallOptions} [gaxOptions] The request configuration options,
1427
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
1428
- * for more details.
1429
- */
1430
- /**
1431
- * @typedef {array} RestoreDatabaseResponse
1432
- * @property {Database} 0 The new {@link Database}.
1433
- * @property {google.longrunning.Operation} 1 An {@link Operation} object that can be used to check
1434
- * the status of the request.
1435
- * @property {object} 2 The full API response.
1436
- */
1437
- /**
1438
- * @callback RestoreDatabaseCallback
1439
- * @param {?Error} err Request error, if any.
1440
- * @param {Database} database The new {@link Database}.
1441
- * @param {google.longrunning.Operation} operation An {@link Operation} object that can be used to
1442
- * check the status of the request.
1443
- * @param {object} apiResponse The full API response.
1444
- */
1445
- /**
1446
- * Restore a backup into this database.
1447
- *
1448
- * When this call completes, the restore will have commenced but will not
1449
- * necessarily have completed.
1450
- *
1451
- * @param {string} backupPath The path of the backup to restore.
1452
- * @param {RestoreOptions} [options] Request configuration options.
1453
- * @param {RestoreDatabaseCallback} [callback] Callback function.
1454
- * @returns {Promise<RestoreDatabaseResponse>} When resolved, contains the restore operation.
1455
- *
1456
- * @example
1457
- * const {Spanner} = require('@google-cloud/spanner');
1458
- * const spanner = new Spanner();
1459
- * const instance = spanner.instance('my-instance');
1460
- * const database = instance.database('my-database');
1461
- * const backupName = 'projects/my-project/instances/my-instance/backups/my-backup';
1462
- * const [, restoreOperation] = await database.restore(backupName);
1463
- * // Wait for restore to complete
1464
- * await restoreOperation.promise();
1465
- *
1466
- * //-
1467
- * // Restore database with a different encryption key to the one used by the
1468
- * // backup.
1469
- * //-
1470
- * const [, restoreWithKeyOperation] = await database.restore(
1471
- * backupName,
1472
- * {
1473
- * encryptionConfig: {
1474
- * encryptionType: 'CUSTOMER_MANAGED_ENCRYPTION',
1475
- * kmsKeyName: 'projects/my-project-id/my-region/keyRings/my-key-ring/cryptoKeys/my-key',
1476
- * }
1477
- * },
1478
- * );
1479
- * // Wait for restore to complete
1480
- * await restoreWithKeyOperation.promise();
1481
- */
1482
652
  restore(backupName, optionsOrCallback, cb) {
1483
653
  const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
1484
654
  const callback = typeof optionsOrCallback === 'function'
@@ -1510,157 +680,6 @@ class Database extends common.GrpcServiceObject {
1510
680
  callback(null, this, operation, resp);
1511
681
  });
1512
682
  }
1513
- /**
1514
- * Transaction options.
1515
- *
1516
- * @typedef {object} DatabaseRunRequest
1517
- * @property {number} [exactStaleness] Executes all reads at the timestamp
1518
- * that is `exactStaleness` old.
1519
- * @property {date} [readTimestamp] Execute all reads at the given
1520
- * timestamp.
1521
- * @property {boolean} [strong] Read at the timestamp where all previously
1522
- * committed transactions are visible.
1523
- */
1524
- /**
1525
- * @typedef {array} RunResponse
1526
- * @property {Array<Row | Json>} 0 Rows are returned as an array objects. Each
1527
- * object has a `name` and `value` property. To get a serialized object,
1528
- * call `toJSON()`.
1529
- * @property {?google.spanner.v1.IResultSetStats} 1 Query statistics, if the query is executed in
1530
- * PLAN or PROFILE mode.
1531
- */
1532
- /**
1533
- * @callback RunCallback
1534
- * @param {?Error} err Request error, if any.
1535
- * @param {Array<Row | Json>} rows Rows are returned as an array of objects.
1536
- * Each object has a `name` and `value` property. To get a serialized
1537
- * object, call `toJSON()`.
1538
- * @param {?google.spanner.v1.IResultSetStats} stats Query statistics, if the query is executed
1539
- * in PLAN or PROFILE mode.
1540
- */
1541
- /**
1542
- * Execute a SQL statement on this database.
1543
- *
1544
- * Wrapper around {@link v1.SpannerClient#executeStreamingSql}.
1545
- *
1546
- * @see {@link v1.SpannerClient#executeStreamingSql}
1547
- * @see [Query Syntax](https://cloud.google.com/spanner/docs/query-syntax)
1548
- * @see [ExecuteSql API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.ExecuteSql)
1549
- *
1550
- * @param {string|ExecuteSqlRequest} query A SQL query or
1551
- * {@link ExecuteSqlRequest} object.
1552
- * @param {TimestampBounds} [options] Snapshot timestamp bounds.
1553
- * @param {RunCallback} [callback] Callback function.
1554
- * @returns {Promise<RunResponse>}
1555
- *
1556
- * @example
1557
- * const {Spanner} = require('@google-cloud/spanner');
1558
- * const spanner = new Spanner();
1559
- *
1560
- * const instance = spanner.instance('my-instance');
1561
- * const database = instance.database('my-database');
1562
- *
1563
- * const query = 'SELECT * FROM Singers';
1564
- *
1565
- * database.run(query, function(err, rows) {
1566
- * if (err) {
1567
- * // Error handling omitted.
1568
- * }
1569
- *
1570
- * const firstRow = rows[0];
1571
- *
1572
- * // firstRow = [
1573
- * // {
1574
- * // name: 'SingerId',
1575
- * // value: '1'
1576
- * // },
1577
- * // {
1578
- * // name: 'Name',
1579
- * // value: 'Eddie Wilson'
1580
- * // }
1581
- * // ]
1582
- * });
1583
- *
1584
- * //-
1585
- * // Rows are returned as an array of object arrays. Each object has a `name`
1586
- * // and `value` property. To get a serialized object, call `toJSON()`.
1587
- * //-
1588
- * database.run(query, function(err, rows) {
1589
- * if (err) {
1590
- * // Error handling omitted.
1591
- * }
1592
- *
1593
- * const firstRow = rows[0];
1594
- *
1595
- * // firstRow.toJSON() = {
1596
- * // SingerId: '1',
1597
- * // Name: 'Eddie Wilson'
1598
- * // }
1599
- * });
1600
- *
1601
- * //-
1602
- * // Alternatively, set `query.json` to `true`, and this step will be performed
1603
- * // automatically.
1604
- * //-
1605
- * database.run(query, function(err, rows) {
1606
- * if (err) {
1607
- * // Error handling omitted.
1608
- * }
1609
- *
1610
- * const firstRow = rows[0];
1611
- *
1612
- * // firstRow = {
1613
- * // SingerId: '1',
1614
- * // Name: 'Eddie Wilson'
1615
- * // }
1616
- * });
1617
- *
1618
- * //-
1619
- * // The SQL query string can contain parameter placeholders. A parameter
1620
- * // placeholder consists of '@' followed by the parameter name.
1621
- * //-
1622
- * const query = {
1623
- * sql: 'SELECT * FROM Singers WHERE name = @name',
1624
- * params: {
1625
- * name: 'Eddie Wilson'
1626
- * }
1627
- * };
1628
- *
1629
- * database.run(query, function(err, rows) {});
1630
- *
1631
- * //-
1632
- * // If you need to enforce a specific param type, a types map can be provided.
1633
- * // This is typically useful if your param value can be null.
1634
- * //-
1635
- * const query = {
1636
- * sql: 'SELECT * FROM Singers WHERE name = @name AND id = @id',
1637
- * params: {
1638
- * id: spanner.int(8),
1639
- * name: null
1640
- * },
1641
- * types: {
1642
- * id: 'int64',
1643
- * name: 'string'
1644
- * }
1645
- * };
1646
- *
1647
- * database.run(query, function(err, rows) {});
1648
- *
1649
- * //-
1650
- * // If the callback is omitted, we'll return a Promise.
1651
- * //-
1652
- * database.run(query).then(function(data) {
1653
- * const rows = data[0];
1654
- * });
1655
- *
1656
- * @example <caption>include:samples/crud.js</caption>
1657
- * region_tag:spanner_query_data
1658
- * Full example:
1659
- *
1660
- * @example <caption>include:samples/index-query-data.js</caption>
1661
- * region_tag:spanner_query_data_with_index
1662
- * Querying data with an index:
1663
- */
1664
683
  run(query, optionsOrCallback, cb) {
1665
684
  let stats;
1666
685
  let metadata;
@@ -1686,20 +705,6 @@ class Database extends common.GrpcServiceObject {
1686
705
  callback(null, rows, stats, metadata);
1687
706
  });
1688
707
  }
1689
- /**
1690
- * Partitioned DML transactions are used to execute DML statements with a
1691
- * different execution strategy that provides different, and often better,
1692
- * scalability properties for large, table-wide operations than DML in a
1693
- * Transaction transaction. Smaller scoped statements, such as an OLTP workload,
1694
- * should prefer using Transaction transactions.
1695
- *
1696
- * @see {@link Transaction#runUpdate}
1697
- *
1698
- * @param {string|ExecuteSqlRequest} query A DML statement or
1699
- * {@link ExecuteSqlRequest} object.
1700
- * @param {RunUpdateCallback} [callback] Callback function.
1701
- * @returns {Promise<RunUpdateResponse>}
1702
- */
1703
708
  runPartitionedUpdate(query, callback) {
1704
709
  this.pool_.getReadSession((err, session) => {
1705
710
  if (err) {
@@ -1752,6 +757,7 @@ class Database extends common.GrpcServiceObject {
1752
757
  * @returns {PartialResultStream} A readable stream that emits rows.
1753
758
  *
1754
759
  * @example
760
+ * ```
1755
761
  * const {Spanner} = require('@google-cloud/spanner');
1756
762
  * const spanner = new Spanner();
1757
763
  *
@@ -1856,6 +862,7 @@ class Database extends common.GrpcServiceObject {
1856
862
  * .on('data', function(row) {
1857
863
  * this.end();
1858
864
  * });
865
+ * ```
1859
866
  */
1860
867
  runStream(query, options) {
1861
868
  const proxyStream = through.obj();
@@ -1901,93 +908,6 @@ class Database extends common.GrpcServiceObject {
1901
908
  });
1902
909
  return proxyStream;
1903
910
  }
1904
- /**
1905
- * @typedef {object} RunTransactionOptions
1906
- * @property {number} [timeout] The maximum amount of time (in ms) that a
1907
- * {@link Transaction} should be ran for.
1908
- */
1909
- /**
1910
- * @callback RunTransactionCallback
1911
- * @param {?Error} err An error returned while making this request.
1912
- * @param {Transaction} transaction The transaction object. The transaction has
1913
- * already been created, and is ready to be queried and committed against.
1914
- */
1915
- /**
1916
- * A transaction in Cloud Spanner is a set of reads and writes that execute
1917
- * atomically at a single logical point in time across columns, rows, and tables
1918
- * in a database.
1919
- *
1920
- * Note that Cloud Spanner does not support nested transactions. If a new
1921
- * transaction is started inside of the run function, it will be an independent
1922
- * transaction.
1923
- *
1924
- * The callback you provide to this function will become the "run function". It
1925
- * will be executed with either an error or a {@link Transaction}
1926
- * object. The Transaction object will let you run queries and queue mutations
1927
- * until you are ready to {@link Transaction#commit}.
1928
- *
1929
- * In the event that an aborted error occurs, we will re-run the `runFn` in its
1930
- * entirety. If you prefer to handle aborted errors for yourself please refer to
1931
- * {@link Database#getTransaction}.
1932
- *
1933
- * **NOTE:** In the event that you encounter an error while reading/writing,
1934
- * if you decide to forgo calling {@link Transaction#commit} or
1935
- * {@link Transaction#rollback}, then you need to call
1936
- * {@link Transaction#end} to release the underlying {@link Session} object.
1937
- * **Failure to do could result in a Session leak.**
1938
- *
1939
- * For a more complete listing of functionality available to a Transaction, see
1940
- * the {@link Transaction} API documentation. For a general overview of
1941
- * transactions within Cloud Spanner, see
1942
- * [Transactions](https://cloud.google.com/spanner/docs/transactions) from the
1943
- * official Cloud Spanner documentation.
1944
- *
1945
- * If you would like to run a transaction and receive a promise or use
1946
- * async/await, use {@link Database#runTransactionAsync}.
1947
- *
1948
- * @see [Transactions](https://cloud.google.com/spanner/docs/transactions)
1949
- *
1950
- * @param {RunTransactionOptions} [options] Transaction runner options.
1951
- * @param {RunTransactionCallback} callback A function to execute in the context
1952
- * of a transaction.
1953
- *
1954
- * @example
1955
- * const {Spanner} = require('@google-cloud/spanner');
1956
- * const spanner = new Spanner();
1957
- *
1958
- * const instance = spanner.instance('my-instance');
1959
- * const database = instance.database('my-database');
1960
- *
1961
- * database.runTransaction(function(err, transaction) {
1962
- * if (err) {
1963
- * // Error handling omitted.
1964
- * }
1965
- *
1966
- * // Run a transactional query.
1967
- * transaction.run('SELECT * FROM Singers', function(err, rows) {
1968
- * if (err) {
1969
- * // Error handling omitted.
1970
- * }
1971
- *
1972
- * // Queue a mutation (note that there is no callback passed to `insert`).
1973
- * transaction.insert('Singers', {
1974
- * SingerId: 'Id3b',
1975
- * Name: 'Joe West'
1976
- * });
1977
- *
1978
- * // Commit the transaction.
1979
- * transaction.commit(function(err) {
1980
- * if (!err) {
1981
- * // Transaction committed successfully.
1982
- * }
1983
- * });
1984
- * });
1985
- * });
1986
- *
1987
- * @example <caption>include:samples/transaction.js</caption>
1988
- * region_tag:spanner_read_write_transaction
1989
- * Read-write transaction:
1990
- */
1991
911
  runTransaction(optionsOrRunFn, fn) {
1992
912
  const runFn = typeof optionsOrRunFn === 'function'
1993
913
  ? optionsOrRunFn
@@ -2061,6 +981,7 @@ class Database extends common.GrpcServiceObject {
2061
981
  * @returns {Promise}
2062
982
  *
2063
983
  * @example
984
+ * ```
2064
985
  * const {Spanner} = require('@google-cloud/spanner');
2065
986
  * const spanner = new Spanner();
2066
987
  *
@@ -2074,6 +995,7 @@ class Database extends common.GrpcServiceObject {
2074
995
  * await transaction.commit();
2075
996
  * return data;
2076
997
  * });
998
+ * ```
2077
999
  */
2078
1000
  async runTransactionAsync(optionsOrRunFn, fn) {
2079
1001
  const runFn = typeof optionsOrRunFn === 'function'
@@ -2116,7 +1038,9 @@ class Database extends common.GrpcServiceObject {
2116
1038
  * @returns {Session} A Session object.
2117
1039
  *
2118
1040
  * @example
1041
+ * ```
2119
1042
  * var session = database.session('session-name');
1043
+ * ```
2120
1044
  */
2121
1045
  session(name) {
2122
1046
  return new session_1.Session(this, name);
@@ -2124,12 +1048,13 @@ class Database extends common.GrpcServiceObject {
2124
1048
  /**
2125
1049
  * Get a reference to a Table object.
2126
1050
  *
2127
- * @throws {Error} If a name is not provided.
1051
+ * @throws {GoogleError} If a name is not provided.
2128
1052
  *
2129
1053
  * @param {string} name The name of the table.
2130
1054
  * @return {Table} A Table object.
2131
1055
  *
2132
1056
  * @example
1057
+ * ```
2133
1058
  * const {Spanner} = require('@google-cloud/spanner');
2134
1059
  * const spanner = new Spanner();
2135
1060
  *
@@ -2137,89 +1062,14 @@ class Database extends common.GrpcServiceObject {
2137
1062
  * const database = instance.database('my-database');
2138
1063
  *
2139
1064
  * const table = database.table('Singers');
1065
+ * ```
2140
1066
  */
2141
1067
  table(name) {
2142
1068
  if (!name) {
2143
- throw new Error('A name is required to access a Table object.');
1069
+ throw new google_gax_1.GoogleError('A name is required to access a Table object.');
2144
1070
  }
2145
1071
  return new table_1.Table(this, name);
2146
1072
  }
2147
- /**
2148
- * Update the schema of the database by creating/altering/dropping tables,
2149
- * columns, indexes, etc.
2150
- *
2151
- * This method immediately responds with an Operation object. Register event
2152
- * handlers for the "error" and "complete" events to see how the operation
2153
- * finishes. Follow along with the examples below.
2154
- *
2155
- * Wrapper around {@link v1.DatabaseAdminClient#updateDatabaseDdl}.
2156
- *
2157
- * @see {@link v1.DatabaseAdminClient#updateDatabaseDdl}
2158
- * @see [Data Definition Language (DDL)](https://cloud.google.com/spanner/docs/data-definition-language)
2159
- * @see [Schema and Data Model](https://cloud.google.com/spanner/docs/schema-and-data-model)
2160
- * @see [UpdateDatabaseDdl API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.UpdateDatabaseDdlRequest)
2161
- *
2162
- * @param {string|string[]|object} statements An array of database DDL
2163
- * statements, or an
2164
- * [`UpdateDatabaseDdlRequest` object](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.UpdateDatabaseDdlRequest).
2165
- * @param {object} [gaxOptions] Request configuration options,
2166
- * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
2167
- * for more details.
2168
- * @param {LongRunningOperationCallback} [callback] Callback function.
2169
- * @returns {Promise<LongRunningOperationResponse>}
2170
- *
2171
- * @example
2172
- * const {Spanner} = require('@google-cloud/spanner');
2173
- * const spanner = new Spanner();
2174
- *
2175
- * const instance = spanner.instance('my-instance');
2176
- * const database = instance.database('my-database');
2177
- *
2178
- * const statements = [
2179
- * 'CREATE TABLE Singers (' +
2180
- * ' SingerId INT64 NOT NULL,' +
2181
- * ' FirstName STRING(1024),' +
2182
- * ' LastName STRING(1024),' +
2183
- * ' SingerInfo BYTES(MAX),' +
2184
- * ') PRIMARY KEY(SingerId)'
2185
- * ];
2186
- *
2187
- * database.updateSchema(statements, function(err, operation, apiResponse) {
2188
- * if (err) {
2189
- * // Error handling omitted.
2190
- * }
2191
- *
2192
- * operation
2193
- * .on('error', function(err) {})
2194
- * .on('complete', function() {
2195
- * // Database schema updated successfully.
2196
- * });
2197
- * });
2198
- *
2199
- * //-
2200
- * // If the callback is omitted, we'll return a Promise.
2201
- * //-
2202
- * database.updateSchema(statements)
2203
- * .then(function(data) {
2204
- * const operation = data[0];
2205
- * return operation.promise();
2206
- * })
2207
- * .then(function() {
2208
- * // Database schema updated successfully.
2209
- * });
2210
- *
2211
- * @example <caption>include:samples/schema.js</caption>
2212
- * region_tag:spanner_add_column
2213
- * Adding a column:
2214
- *
2215
- * @example <caption>include:samples/index-create.js</caption>
2216
- * region_tag:spanner_create_index
2217
- * Creating an index:
2218
- *
2219
- * @example <caption>include:samples/index-create-stroing.js</caption>
2220
- * region_tag:spanner_create_storing_index
2221
- * Creating a storing index:
2222
- */
2223
1073
  updateSchema(statements, optionsOrCallback, cb) {
2224
1074
  const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
2225
1075
  const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
@@ -2249,11 +1099,13 @@ class Database extends common.GrpcServiceObject {
2249
1099
  * @returns {string}
2250
1100
  *
2251
1101
  * @example
1102
+ * ```
2252
1103
  * Database.formatName_(
2253
1104
  * 'projects/grape-spaceship-123/instances/my-instance',
2254
1105
  * 'my-database'
2255
1106
  * );
2256
1107
  * // 'projects/grape-spaceship-123/instances/my-instance/databases/my-database'
1108
+ * ```
2257
1109
  */
2258
1110
  static formatName_(instanceName, name) {
2259
1111
  if (name.indexOf('/') > -1) {