@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.
- package/CHANGELOG.md +34 -0
- package/README.md +57 -57
- package/build/protos/protos.d.ts +3 -2
- package/build/protos/protos.js +8 -1
- package/build/protos/protos.json +14 -1
- package/build/src/backup.d.ts +214 -0
- package/build/src/backup.js +4 -196
- package/build/src/batch-transaction.d.ts +6 -0
- package/build/src/batch-transaction.js +6 -0
- package/build/src/codec.d.ts +4 -0
- package/build/src/codec.js +4 -0
- package/build/src/database.d.ts +1244 -22
- package/build/src/database.js +36 -1184
- package/build/src/index.d.ts +366 -17
- package/build/src/index.js +39 -312
- package/build/src/instance.d.ts +526 -0
- package/build/src/instance.js +18 -498
- package/build/src/partial-result-stream.d.ts +1 -1
- package/build/src/partial-result-stream.js +2 -1
- package/build/src/session-pool.d.ts +5 -5
- package/build/src/session-pool.js +13 -8
- package/build/src/session.d.ts +98 -0
- package/build/src/session.js +16 -82
- package/build/src/table.d.ts +645 -0
- package/build/src/table.js +4 -623
- package/build/src/transaction.d.ts +509 -19
- package/build/src/transaction.js +60 -443
- package/build/src/v1/database_admin_client.d.ts +666 -40
- package/build/src/v1/database_admin_client.js +32 -706
- package/build/src/v1/gapic_metadata.json +1 -1
- package/build/src/v1/instance_admin_client.d.ts +357 -20
- package/build/src/v1/instance_admin_client.js +16 -377
- package/build/src/v1/spanner_client.d.ts +586 -13
- package/build/src/v1/spanner_client.js +10 -596
- package/package.json +2 -2
|
@@ -147,6 +147,7 @@ export declare type CommitCallback = NormalCallback<spannerClient.spanner.v1.ICo
|
|
|
147
147
|
* @see [Timestamp Bounds API Documentation](https://cloud.google.com/spanner/docs/timestamp-bounds)
|
|
148
148
|
*
|
|
149
149
|
* @example
|
|
150
|
+
* ```
|
|
150
151
|
* const {Spanner} = require('@google-cloud/spanner');
|
|
151
152
|
* const spanner = new Spanner();
|
|
152
153
|
*
|
|
@@ -165,6 +166,7 @@ export declare type CommitCallback = NormalCallback<spannerClient.spanner.v1.ICo
|
|
|
165
166
|
* // It should be called when the snapshot finishes.
|
|
166
167
|
* transaction.end();
|
|
167
168
|
* });
|
|
169
|
+
* ```
|
|
168
170
|
*/
|
|
169
171
|
export declare class Snapshot extends EventEmitter {
|
|
170
172
|
protected _options: spannerClient.spanner.v1.ITransactionOptions;
|
|
@@ -226,6 +228,50 @@ export declare class Snapshot extends EventEmitter {
|
|
|
226
228
|
* are specified for a query.
|
|
227
229
|
*/
|
|
228
230
|
constructor(session: Session, options?: TimestampBounds, queryOptions?: IQueryOptions);
|
|
231
|
+
/**
|
|
232
|
+
* @typedef {object} TransactionResponse
|
|
233
|
+
* @property {string|Buffer} id The transaction ID.
|
|
234
|
+
* @property {?google.protobuf.Timestamp} readTimestamp For snapshot read-only
|
|
235
|
+
* transactions, the read timestamp chosen for the transaction.
|
|
236
|
+
*/
|
|
237
|
+
/**
|
|
238
|
+
* @typedef {array} TransactionBeginResponse
|
|
239
|
+
* @property {TransactionResponse} 0 The raw transaction object.
|
|
240
|
+
*/
|
|
241
|
+
/**
|
|
242
|
+
* @callback TransactionBeginCallback
|
|
243
|
+
* @param {?Error} err Request error, if any.
|
|
244
|
+
* @param {TransactionResponse} apiResponse The raw transaction object.
|
|
245
|
+
*/
|
|
246
|
+
/**
|
|
247
|
+
* Begin a new transaction. Typically, you need not call this unless
|
|
248
|
+
* manually creating transactions via {@link Session} objects.
|
|
249
|
+
*
|
|
250
|
+
* @see [BeginTransaction API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.BeginTransaction)
|
|
251
|
+
*
|
|
252
|
+
* @param {object} [gaxOptions] Request configuration options,
|
|
253
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
254
|
+
* for more details.
|
|
255
|
+
* @param {TransactionBeginCallback} [callback] Callback function.
|
|
256
|
+
* @returns {Promise<TransactionBeginResponse>}
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```
|
|
260
|
+
* transaction.begin(function(err) {
|
|
261
|
+
* if (!err) {
|
|
262
|
+
* // transaction began successfully.
|
|
263
|
+
* }
|
|
264
|
+
* });
|
|
265
|
+
*
|
|
266
|
+
* ```
|
|
267
|
+
* @example If the callback is omitted, the function returns a Promise
|
|
268
|
+
* ```
|
|
269
|
+
* transaction.begin()
|
|
270
|
+
* .then(function(data) {
|
|
271
|
+
* const apiResponse = data[0];
|
|
272
|
+
* });
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
229
275
|
begin(gaxOptions?: CallOptions): Promise<BeginResponse>;
|
|
230
276
|
begin(callback: BeginTransactionCallback): void;
|
|
231
277
|
begin(gaxOptions: CallOptions, callback: BeginTransactionCallback): void;
|
|
@@ -304,6 +350,7 @@ export declare class Snapshot extends EventEmitter {
|
|
|
304
350
|
* @returns {ReadableStream} A readable stream that emits rows.
|
|
305
351
|
*
|
|
306
352
|
* @example
|
|
353
|
+
* ```
|
|
307
354
|
* transaction.createReadStream('Singers', {
|
|
308
355
|
* keys: ['1'],
|
|
309
356
|
* columns: ['SingerId', 'name']
|
|
@@ -325,8 +372,10 @@ export declare class Snapshot extends EventEmitter {
|
|
|
325
372
|
* // All results retrieved.
|
|
326
373
|
* });
|
|
327
374
|
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
375
|
+
* ```
|
|
376
|
+
* @example Provide an array for `query.keys` to read with a
|
|
377
|
+
* composite key.
|
|
378
|
+
* ```
|
|
330
379
|
* const query = {
|
|
331
380
|
* keys: [
|
|
332
381
|
* [
|
|
@@ -340,10 +389,12 @@ export declare class Snapshot extends EventEmitter {
|
|
|
340
389
|
* ],
|
|
341
390
|
* // ...
|
|
342
391
|
* };
|
|
392
|
+
* ```
|
|
343
393
|
*
|
|
344
|
-
* @example
|
|
394
|
+
* @example Rows are returned as an array of object arrays. Each
|
|
345
395
|
* object has a `name` and `value` property. To get a serialized object, call
|
|
346
|
-
* `toJSON()
|
|
396
|
+
* `toJSON()`.
|
|
397
|
+
* ```
|
|
347
398
|
* transaction.createReadStream('Singers', {
|
|
348
399
|
* keys: ['1'],
|
|
349
400
|
* columns: ['SingerId', 'name']
|
|
@@ -358,9 +409,11 @@ export declare class Snapshot extends EventEmitter {
|
|
|
358
409
|
* .on('end', function() {
|
|
359
410
|
* // All results retrieved.
|
|
360
411
|
* });
|
|
412
|
+
* ```
|
|
361
413
|
*
|
|
362
|
-
* @example
|
|
363
|
-
* will perform automatically
|
|
414
|
+
* @example Alternatively, set `query.json` to `true`, and this step
|
|
415
|
+
* will perform automatically.
|
|
416
|
+
* ```
|
|
364
417
|
* transaction.createReadStream('Singers', {
|
|
365
418
|
* keys: ['1'],
|
|
366
419
|
* columns: ['SingerId', 'name'],
|
|
@@ -376,9 +429,11 @@ export declare class Snapshot extends EventEmitter {
|
|
|
376
429
|
* .on('end', function() {
|
|
377
430
|
* // All results retrieved.
|
|
378
431
|
* });
|
|
432
|
+
* ```
|
|
379
433
|
*
|
|
380
|
-
* @example
|
|
381
|
-
* early to prevent unnecessary processing and API requests
|
|
434
|
+
* @example If you anticipate many results, you can end a stream
|
|
435
|
+
* early to prevent unnecessary processing and API requests.
|
|
436
|
+
* ```
|
|
382
437
|
* transaction.createReadStream('Singers', {
|
|
383
438
|
* keys: ['1'],
|
|
384
439
|
* columns: ['SingerId', 'name']
|
|
@@ -386,6 +441,7 @@ export declare class Snapshot extends EventEmitter {
|
|
|
386
441
|
* .on('data', function(row) {
|
|
387
442
|
* this.end();
|
|
388
443
|
* });
|
|
444
|
+
* ```
|
|
389
445
|
*/
|
|
390
446
|
createReadStream(table: string, request?: ReadRequest): PartialResultStream;
|
|
391
447
|
/**
|
|
@@ -393,7 +449,8 @@ export declare class Snapshot extends EventEmitter {
|
|
|
393
449
|
* mainly be called for {@link Snapshot} objects, however in certain cases
|
|
394
450
|
* you may want to call them for {@link Transaction} objects as well.
|
|
395
451
|
*
|
|
396
|
-
* @example
|
|
452
|
+
* @example Calling `end` on a read only snapshot
|
|
453
|
+
* ```
|
|
397
454
|
* database.getSnapshot((err, transaction) => {
|
|
398
455
|
* if (err) {
|
|
399
456
|
* // Error handling omitted.
|
|
@@ -408,8 +465,10 @@ export declare class Snapshot extends EventEmitter {
|
|
|
408
465
|
* transaction.end();
|
|
409
466
|
* });
|
|
410
467
|
* });
|
|
468
|
+
* ```
|
|
411
469
|
*
|
|
412
|
-
* @example
|
|
470
|
+
* @example Calling `end` on a read/write transaction
|
|
471
|
+
* ```
|
|
413
472
|
* database.runTransaction((err, transaction) => {
|
|
414
473
|
* if (err) {
|
|
415
474
|
* // Error handling omitted.
|
|
@@ -428,11 +487,206 @@ export declare class Snapshot extends EventEmitter {
|
|
|
428
487
|
* transaction.commit(err => {});
|
|
429
488
|
* });
|
|
430
489
|
* });
|
|
490
|
+
* ```
|
|
431
491
|
*/
|
|
432
492
|
end(): void;
|
|
493
|
+
/**
|
|
494
|
+
* @typedef {array} ReadResponse
|
|
495
|
+
* @property {array[]} 0 Rows are returned as an array of object arrays. Each
|
|
496
|
+
* object has a `name` and `value` property. To get a serialized object,
|
|
497
|
+
* call `toJSON()`. Optionally, provide an options object to `toJSON()`
|
|
498
|
+
* specifying `wrapNumbers: true` to protect large integer values outside
|
|
499
|
+
* of the range of JavaScript Number. If set, FLOAT64 values are returned
|
|
500
|
+
* as {@link Spanner.Float} objects and INT64 values as {@link
|
|
501
|
+
* Spanner.Int}.
|
|
502
|
+
*/
|
|
503
|
+
/**
|
|
504
|
+
* @callback ReadCallback
|
|
505
|
+
* @param {?Error} err Request error, if any.
|
|
506
|
+
* @param {array[]} rows Rows are returned as an array of object arrays. Each
|
|
507
|
+
* object has a `name` and `value` property. To get a serialized object,
|
|
508
|
+
* call `toJSON()`. Optionally, provide an options object to `toJSON()`
|
|
509
|
+
* specifying `wrapNumbers: true` to protect large integer values outside
|
|
510
|
+
* of the range of JavaScript Number. If set, FLOAT64 values are returned
|
|
511
|
+
* as {@link Spanner.Float} objects and INT64 values as {@link
|
|
512
|
+
* Spanner.Int}.
|
|
513
|
+
*/
|
|
514
|
+
/**
|
|
515
|
+
* Performs a read request against the specified Table.
|
|
516
|
+
*
|
|
517
|
+
* Wrapper around {@link v1.SpannerClient#read}.
|
|
518
|
+
*
|
|
519
|
+
* @see {@link v1.SpannerClient#read}
|
|
520
|
+
*
|
|
521
|
+
* @param {string} table The table to read from.
|
|
522
|
+
* @param {ReadRequest} query Configuration object. See official
|
|
523
|
+
* [`ReadRequest`](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ReadRequest).
|
|
524
|
+
* API documentation.
|
|
525
|
+
* @param {ReadCallback} [callback] Callback function.
|
|
526
|
+
* @returns {Promise<ReadResponse>}
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* ```
|
|
530
|
+
* const query = {
|
|
531
|
+
* keys: ['1'],
|
|
532
|
+
* columns: ['SingerId', 'name']
|
|
533
|
+
* };
|
|
534
|
+
*
|
|
535
|
+
* transaction.read('Singers', query, function(err, rows) {
|
|
536
|
+
* if (err) {
|
|
537
|
+
* // Error handling omitted.
|
|
538
|
+
* }
|
|
539
|
+
*
|
|
540
|
+
* const firstRow = rows[0];
|
|
541
|
+
*
|
|
542
|
+
* // firstRow = [
|
|
543
|
+
* // {
|
|
544
|
+
* // name: 'SingerId',
|
|
545
|
+
* // value: '1'
|
|
546
|
+
* // },
|
|
547
|
+
* // {
|
|
548
|
+
* // name: 'Name',
|
|
549
|
+
* // value: 'Eddie Wilson'
|
|
550
|
+
* // }
|
|
551
|
+
* // ]
|
|
552
|
+
* });
|
|
553
|
+
*
|
|
554
|
+
* ```
|
|
555
|
+
* @example Provide an array for `query.keys` to read with a
|
|
556
|
+
* composite key.
|
|
557
|
+
* ```
|
|
558
|
+
* const query = {
|
|
559
|
+
* keys: [
|
|
560
|
+
* [
|
|
561
|
+
* 'Id1',
|
|
562
|
+
* 'Name1'
|
|
563
|
+
* ],
|
|
564
|
+
* [
|
|
565
|
+
* 'Id2',
|
|
566
|
+
* 'Name2'
|
|
567
|
+
* ]
|
|
568
|
+
* ],
|
|
569
|
+
* // ...
|
|
570
|
+
* };
|
|
571
|
+
* ```
|
|
572
|
+
*
|
|
573
|
+
* @example Rows are returned as an array of object arrays. Each
|
|
574
|
+
* object has a `name` and `value` property. To get a serialized object, call
|
|
575
|
+
* `toJSON()`.
|
|
576
|
+
* ```
|
|
577
|
+
* transaction.read('Singers', query, function(err, rows) {
|
|
578
|
+
* if (err) {
|
|
579
|
+
* // Error handling omitted.
|
|
580
|
+
* }
|
|
581
|
+
*
|
|
582
|
+
* const firstRow = rows[0];
|
|
583
|
+
*
|
|
584
|
+
* // firstRow.toJSON() = {
|
|
585
|
+
* // SingerId: '1',
|
|
586
|
+
* // Name: 'Eddie Wilson'
|
|
587
|
+
* // }
|
|
588
|
+
* });
|
|
589
|
+
* ```
|
|
590
|
+
*
|
|
591
|
+
* @example Alternatively, set `query.json` to `true`, and this step
|
|
592
|
+
* will perform automatically.
|
|
593
|
+
* ```
|
|
594
|
+
* query.json = true;
|
|
595
|
+
*
|
|
596
|
+
* transaction.read('Singers', query, function(err, rows) {
|
|
597
|
+
* if (err) {
|
|
598
|
+
* // Error handling omitted.
|
|
599
|
+
* }
|
|
600
|
+
*
|
|
601
|
+
* const firstRow = rows[0];
|
|
602
|
+
*
|
|
603
|
+
* // firstRow = {
|
|
604
|
+
* // SingerId: '1',
|
|
605
|
+
* // Name: 'Eddie Wilson'
|
|
606
|
+
* // }
|
|
607
|
+
* });
|
|
608
|
+
* ```
|
|
609
|
+
*/
|
|
433
610
|
read(table: string, request: ReadRequest): Promise<ReadResponse>;
|
|
434
611
|
read(table: string, callback: ReadCallback): void;
|
|
435
612
|
read(table: string, request: ReadRequest, callback: ReadCallback): void;
|
|
613
|
+
/**
|
|
614
|
+
* Execute a SQL statement on this database inside of a transaction.
|
|
615
|
+
*
|
|
616
|
+
* **Performance Considerations:**
|
|
617
|
+
*
|
|
618
|
+
* This method wraps the streaming method,
|
|
619
|
+
* {@link Snapshot#run} for your convenience. All rows are stored in memory
|
|
620
|
+
* before releasing to your callback. If you intend to receive a lot of
|
|
621
|
+
* results from your query, consider using the streaming method,
|
|
622
|
+
* so you can free each result from memory after consuming it.
|
|
623
|
+
*
|
|
624
|
+
* Wrapper around {@link v1.SpannerClient#executeStreamingSql}.
|
|
625
|
+
*
|
|
626
|
+
* @see {@link v1.SpannerClient#executeStreamingSql}
|
|
627
|
+
* @see [ExecuteStreamingSql API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.ExecuteStreamingSql)
|
|
628
|
+
* @see [ExecuteSqlRequest API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ExecuteSqlRequest)
|
|
629
|
+
*
|
|
630
|
+
* @param {string|ExecuteSqlRequest} query A SQL query or
|
|
631
|
+
* {@link ExecuteSqlRequest} object.
|
|
632
|
+
* @param {RunCallback} [callback] Callback function.
|
|
633
|
+
* @returns {Promise<RunResponse>}
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* ```
|
|
637
|
+
* transaction.run(query, function(err, rows) {
|
|
638
|
+
* if (err) {
|
|
639
|
+
* // Error handling omitted.
|
|
640
|
+
* }
|
|
641
|
+
*
|
|
642
|
+
* // rows = [
|
|
643
|
+
* // {
|
|
644
|
+
* // SingerId: '1',
|
|
645
|
+
* // Name: 'Eddie Wilson'
|
|
646
|
+
* // }
|
|
647
|
+
* // ]
|
|
648
|
+
* });
|
|
649
|
+
*
|
|
650
|
+
* ```
|
|
651
|
+
* @example The SQL query string can contain parameter placeholders.
|
|
652
|
+
* A parameter placeholder consists of '@' followed by the parameter name.
|
|
653
|
+
* ```
|
|
654
|
+
* const query = {
|
|
655
|
+
* sql: 'SELECT * FROM Singers WHERE name = @name',
|
|
656
|
+
* params: {
|
|
657
|
+
* name: 'Eddie Wilson'
|
|
658
|
+
* }
|
|
659
|
+
* };
|
|
660
|
+
*
|
|
661
|
+
* transaction.run(query, function(err, rows) {
|
|
662
|
+
* if (err) {
|
|
663
|
+
* // Error handling omitted.
|
|
664
|
+
* }
|
|
665
|
+
* });
|
|
666
|
+
* ```
|
|
667
|
+
*
|
|
668
|
+
* @example If you need to enforce a specific param type, a types map
|
|
669
|
+
* can be provided. This is typically useful if your param value can be null.
|
|
670
|
+
* ```
|
|
671
|
+
* const query = {
|
|
672
|
+
* sql: 'SELECT * FROM Singers WHERE name = @name AND id = @id',
|
|
673
|
+
* params: {
|
|
674
|
+
* id: spanner.int(8),
|
|
675
|
+
* name: null
|
|
676
|
+
* },
|
|
677
|
+
* types: {
|
|
678
|
+
* id: 'int64',
|
|
679
|
+
* name: 'string'
|
|
680
|
+
* }
|
|
681
|
+
* };
|
|
682
|
+
*
|
|
683
|
+
* transaction.run(query, function(err, rows) {
|
|
684
|
+
* if (err) {
|
|
685
|
+
* // Error handling omitted.
|
|
686
|
+
* }
|
|
687
|
+
* });
|
|
688
|
+
* ```
|
|
689
|
+
*/
|
|
436
690
|
run(query: string | ExecuteSqlRequest): Promise<RunResponse>;
|
|
437
691
|
run(query: string | ExecuteSqlRequest, callback: RunCallback): void;
|
|
438
692
|
/**
|
|
@@ -491,6 +745,7 @@ export declare class Snapshot extends EventEmitter {
|
|
|
491
745
|
* @returns {ReadableStream}
|
|
492
746
|
*
|
|
493
747
|
* @example
|
|
748
|
+
* ```
|
|
494
749
|
* const query = 'SELECT * FROM Singers';
|
|
495
750
|
*
|
|
496
751
|
* transaction.runStream(query)
|
|
@@ -505,9 +760,10 @@ export declare class Snapshot extends EventEmitter {
|
|
|
505
760
|
* // All results retrieved.
|
|
506
761
|
* });
|
|
507
762
|
*
|
|
508
|
-
*
|
|
763
|
+
* ```
|
|
764
|
+
* @example The SQL query string can contain parameter placeholders.
|
|
509
765
|
* A parameter placeholder consists of '@' followed by the parameter name.
|
|
510
|
-
*
|
|
766
|
+
* ```
|
|
511
767
|
* const query = {
|
|
512
768
|
* sql: 'SELECT * FROM Singers WHERE name = @name',
|
|
513
769
|
* params: {
|
|
@@ -519,13 +775,16 @@ export declare class Snapshot extends EventEmitter {
|
|
|
519
775
|
* .on('error', function(err) {})
|
|
520
776
|
* .on('data', function(row) {})
|
|
521
777
|
* .on('end', function() {});
|
|
778
|
+
* ```
|
|
522
779
|
*
|
|
523
|
-
* @example
|
|
524
|
-
* early to prevent unnecessary processing and API requests
|
|
780
|
+
* @example If you anticipate many results, you can end a stream
|
|
781
|
+
* early to prevent unnecessary processing and API requests.
|
|
782
|
+
* ```
|
|
525
783
|
* transaction.runStream(query)
|
|
526
784
|
* .on('data', function(row) {
|
|
527
785
|
* this.end();
|
|
528
786
|
* });
|
|
787
|
+
* ```
|
|
529
788
|
*/
|
|
530
789
|
runStream(query: string | ExecuteSqlRequest): PartialResultStream;
|
|
531
790
|
/**
|
|
@@ -577,6 +836,30 @@ export declare class Snapshot extends EventEmitter {
|
|
|
577
836
|
* @class
|
|
578
837
|
*/
|
|
579
838
|
export declare class Dml extends Snapshot {
|
|
839
|
+
/**
|
|
840
|
+
* @typedef {array} RunUpdateResponse
|
|
841
|
+
* @property {number} 0 Affected row count.
|
|
842
|
+
*/
|
|
843
|
+
/**
|
|
844
|
+
* @callback RunUpdateCallback
|
|
845
|
+
* @param {?Error} err Request error, if any.
|
|
846
|
+
* @param {number} rowCount Affected row count.
|
|
847
|
+
*/
|
|
848
|
+
/**
|
|
849
|
+
* Execute a DML statement and get the affected row count.
|
|
850
|
+
*
|
|
851
|
+
* @private
|
|
852
|
+
*
|
|
853
|
+
* @see {@link Transaction#run}
|
|
854
|
+
*
|
|
855
|
+
* @param {string|object} query A DML statement or
|
|
856
|
+
* [`ExecuteSqlRequest`](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ExecuteSqlRequest)
|
|
857
|
+
* object.
|
|
858
|
+
* @param {object} [query.params] A map of parameter name to values.
|
|
859
|
+
* @param {object} [query.types] A map of parameter types.
|
|
860
|
+
* @param {RunUpdateCallback} [callback] Callback function.
|
|
861
|
+
* @returns {Promise<RunUpdateResponse>}
|
|
862
|
+
*/
|
|
580
863
|
runUpdate(query: string | ExecuteSqlRequest): Promise<RunUpdateResponse>;
|
|
581
864
|
runUpdate(query: string | ExecuteSqlRequest, callback: RunUpdateCallback): void;
|
|
582
865
|
}
|
|
@@ -605,6 +888,7 @@ export declare class Dml extends Snapshot {
|
|
|
605
888
|
* @param {Session} session The parent Session object.
|
|
606
889
|
*
|
|
607
890
|
* @example
|
|
891
|
+
* ```
|
|
608
892
|
* const {Spanner} = require('@google-cloud/spanner');
|
|
609
893
|
* const spanner = new Spanner();
|
|
610
894
|
*
|
|
@@ -615,11 +899,14 @@ export declare class Dml extends Snapshot {
|
|
|
615
899
|
* // The `transaction` object is ready for use.
|
|
616
900
|
* });
|
|
617
901
|
*
|
|
618
|
-
*
|
|
619
|
-
*
|
|
902
|
+
* ```
|
|
903
|
+
* @example To manually control retrying the transaction, use the
|
|
904
|
+
* `getTransaction` method.
|
|
905
|
+
* ```
|
|
620
906
|
* database.getTransaction(function(err, transaction) {
|
|
621
907
|
* // The `transaction` object is ready for use.
|
|
622
908
|
* });
|
|
909
|
+
* ```
|
|
623
910
|
*/
|
|
624
911
|
export declare class Transaction extends Dml {
|
|
625
912
|
commitTimestamp?: PreciseDate;
|
|
@@ -655,6 +942,7 @@ export declare class Transaction extends Dml {
|
|
|
655
942
|
* @returns {Promise<RunUpdateResponse>}
|
|
656
943
|
*
|
|
657
944
|
* @example
|
|
945
|
+
* ```
|
|
658
946
|
* const query = 'UPDATE Account SET Balance = 1000 WHERE Key = 1';
|
|
659
947
|
*
|
|
660
948
|
* transaction.runUpdate(query, (err, rowCount) => {
|
|
@@ -662,12 +950,144 @@ export declare class Transaction extends Dml {
|
|
|
662
950
|
* // Error handling omitted.
|
|
663
951
|
* }
|
|
664
952
|
* });
|
|
953
|
+
* ```
|
|
665
954
|
*/
|
|
666
955
|
constructor(session: Session, options?: spannerClient.spanner.v1.TransactionOptions.ReadWrite, queryOptions?: IQueryOptions, requestOptions?: Pick<IRequestOptions, 'transactionTag'>);
|
|
956
|
+
/**
|
|
957
|
+
* @typedef {error} BatchUpdateError
|
|
958
|
+
* @property {number} code gRPC status code.
|
|
959
|
+
* @property {?object} metadata gRPC metadata.
|
|
960
|
+
* @property {number[]} rowCounts The affected row counts for any DML
|
|
961
|
+
* statements that were executed successfully before this error occurred.
|
|
962
|
+
*/
|
|
963
|
+
/**
|
|
964
|
+
* @typedef {object} BatchUpdateOptions
|
|
965
|
+
* @property {object} [gaxOptions] Request configuration options,
|
|
966
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
967
|
+
* for more details.
|
|
968
|
+
* @property {google.spanner.v1.IRequestOptions} [requestOptions] The request options to include
|
|
969
|
+
* with the commit request.
|
|
970
|
+
*/
|
|
971
|
+
/**
|
|
972
|
+
* @typedef {array} BatchUpdateResponse
|
|
973
|
+
* @property {number[]} 0 Affected row counts.
|
|
974
|
+
* @property {object} 1 The full API response.
|
|
975
|
+
*/
|
|
976
|
+
/**
|
|
977
|
+
* @callback BatchUpdateCallback
|
|
978
|
+
* @param {?BatchUpdateError} err Request error, if any.
|
|
979
|
+
* @param {number[]} rowCounts Affected row counts.
|
|
980
|
+
* @param {object} apiResponse The full API response.
|
|
981
|
+
*/
|
|
982
|
+
/**
|
|
983
|
+
* Execute a series of DML statements and get the affected row counts.
|
|
984
|
+
*
|
|
985
|
+
* If any of the DML statements fail, the returned error will contain a list
|
|
986
|
+
* of results for all successfully executed statements.
|
|
987
|
+
*
|
|
988
|
+
* @param {string[]|object[]} query A DML statement or
|
|
989
|
+
* [`ExecuteSqlRequest`](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ExecuteSqlRequest)
|
|
990
|
+
* object.
|
|
991
|
+
* @param {object} [query.params] A map of parameter name to values.
|
|
992
|
+
* @param {object} [query.types] A map of parameter types.
|
|
993
|
+
* @param {object} [gaxOptions] Request configuration options,
|
|
994
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
995
|
+
* for more details.
|
|
996
|
+
* @param {BatchUpdateOptions} [options] Options for configuring the request.
|
|
997
|
+
* @param {RunUpdateCallback} [callback] Callback function.
|
|
998
|
+
* @returns {Promise<RunUpdateResponse>}
|
|
999
|
+
*
|
|
1000
|
+
* @example
|
|
1001
|
+
* ```
|
|
1002
|
+
* const queries = [
|
|
1003
|
+
* {
|
|
1004
|
+
* sql: 'INSERT INTO MyTable (Key, Value) VALUES (@key, @value)',
|
|
1005
|
+
* params: {key: 'my-key', value: 'my-value'},
|
|
1006
|
+
* },
|
|
1007
|
+
* {
|
|
1008
|
+
* sql: 'UPDATE MyTable t SET t.Value = @value WHERE t.KEY = @key',
|
|
1009
|
+
* params: {key: 'my-other-key', value: 'my-other-value'}
|
|
1010
|
+
* }
|
|
1011
|
+
* ];
|
|
1012
|
+
*
|
|
1013
|
+
* transaction.batchUpdate(queries, (err, rowCounts, apiResponse) => {
|
|
1014
|
+
* if (err) {
|
|
1015
|
+
* // Error handling omitted.
|
|
1016
|
+
* }
|
|
1017
|
+
* });
|
|
1018
|
+
*
|
|
1019
|
+
* ```
|
|
1020
|
+
* @example If the callback is omitted, we'll return a Promise.
|
|
1021
|
+
* ```
|
|
1022
|
+
* const [rowCounts, apiResponse] = await transaction.batchUpdate(queries);
|
|
1023
|
+
* ```
|
|
1024
|
+
*/
|
|
667
1025
|
batchUpdate(queries: Array<string | Statement>, options?: BatchUpdateOptions | CallOptions): Promise<BatchUpdateResponse>;
|
|
668
1026
|
batchUpdate(queries: Array<string | Statement>, callback: BatchUpdateCallback): void;
|
|
669
1027
|
batchUpdate(queries: Array<string | Statement>, options: BatchUpdateOptions | CallOptions, callback: BatchUpdateCallback): void;
|
|
670
1028
|
private static extractKnownMetadata;
|
|
1029
|
+
/**
|
|
1030
|
+
* @typedef {object} CommitOptions
|
|
1031
|
+
* @property {google.spanner.v1.IRequestOptions} requestOptions The request options to include
|
|
1032
|
+
* with the commit request.
|
|
1033
|
+
* @property {boolean} returnCommitStats Include statistics related to the
|
|
1034
|
+
* transaction in the {@link CommitResponse}.
|
|
1035
|
+
* @property {object} [gaxOptions] The request configuration options,
|
|
1036
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
1037
|
+
* for more details.
|
|
1038
|
+
*/
|
|
1039
|
+
/**
|
|
1040
|
+
* @typedef {object} CommitResponse
|
|
1041
|
+
* @property {google.protobuf.Timestamp} commitTimestamp The transaction
|
|
1042
|
+
* commit timestamp.
|
|
1043
|
+
* @property {google.spanner.v1.CommitResponse.ICommitStats|null} commitStats
|
|
1044
|
+
* The statistics about this commit. Only populated if requested in
|
|
1045
|
+
* {@link CommitOptions}.
|
|
1046
|
+
*/
|
|
1047
|
+
/**
|
|
1048
|
+
* @typedef {array} CommitPromiseResponse
|
|
1049
|
+
* @property {CommitResponse} 0 The commit response.
|
|
1050
|
+
*/
|
|
1051
|
+
/**
|
|
1052
|
+
* @callback CommitCallback
|
|
1053
|
+
* @param {?Error} error Request error, if any.
|
|
1054
|
+
* @param {CommitResponse} apiResponse The full API response.
|
|
1055
|
+
*/
|
|
1056
|
+
/**
|
|
1057
|
+
* Commit the transaction.
|
|
1058
|
+
*
|
|
1059
|
+
* Wrapper around {@link v1.SpannerClient#commit}.
|
|
1060
|
+
*
|
|
1061
|
+
* @see {@link v1.SpannerClient#commit}
|
|
1062
|
+
* @see [Commit API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.Commit)
|
|
1063
|
+
*
|
|
1064
|
+
* @param {CommitOptions} [options] Options for configuring the request.
|
|
1065
|
+
* @param {CommitCallback} [callback] Callback function.
|
|
1066
|
+
* @returns {Promise<CommitPromiseResponse>}
|
|
1067
|
+
*
|
|
1068
|
+
* @example
|
|
1069
|
+
* ```
|
|
1070
|
+
* database.runTransaction(function(err, transaction) {
|
|
1071
|
+
* if (err) {
|
|
1072
|
+
* // Error handling omitted.
|
|
1073
|
+
* }
|
|
1074
|
+
*
|
|
1075
|
+
* // Queue a mutation (note that there is no callback passed to `insert`).
|
|
1076
|
+
* transaction.insert('Singers', {
|
|
1077
|
+
* SingerId: 'Id3b',
|
|
1078
|
+
* Name: 'Joe West'
|
|
1079
|
+
* });
|
|
1080
|
+
*
|
|
1081
|
+
* // Commit the transaction.
|
|
1082
|
+
* transaction.commit(function(err, apiResponse) {
|
|
1083
|
+
* if (!err) {
|
|
1084
|
+
* // Get the commit timestamp on successful commits.
|
|
1085
|
+
* const {commitTimestamp} = apiResponse;
|
|
1086
|
+
* }
|
|
1087
|
+
* });
|
|
1088
|
+
* });
|
|
1089
|
+
* ```
|
|
1090
|
+
*/
|
|
671
1091
|
commit(options?: CommitOptions | CallOptions): Promise<CommitResponse>;
|
|
672
1092
|
commit(callback: CommitCallback): void;
|
|
673
1093
|
commit(options: CommitOptions | CallOptions, callback: CommitCallback): void;
|
|
@@ -702,6 +1122,7 @@ export declare class Transaction extends Dml {
|
|
|
702
1122
|
* below.
|
|
703
1123
|
*
|
|
704
1124
|
* @example
|
|
1125
|
+
* ```
|
|
705
1126
|
* const keys = ['Id1', 'Id2', 'Id3'];
|
|
706
1127
|
*
|
|
707
1128
|
* database.runTransaction(function(err, transaction) {
|
|
@@ -721,8 +1142,10 @@ export declare class Transaction extends Dml {
|
|
|
721
1142
|
* });
|
|
722
1143
|
* });
|
|
723
1144
|
*
|
|
724
|
-
*
|
|
725
|
-
*
|
|
1145
|
+
* ```
|
|
1146
|
+
* @example Provide an array for `keys` to delete rows with a
|
|
1147
|
+
* composite key.
|
|
1148
|
+
* ```
|
|
726
1149
|
* const keys = [
|
|
727
1150
|
* [
|
|
728
1151
|
* 'Id1',
|
|
@@ -733,6 +1156,7 @@ export declare class Transaction extends Dml {
|
|
|
733
1156
|
* 'Name2'
|
|
734
1157
|
* ]
|
|
735
1158
|
* ];
|
|
1159
|
+
* ```
|
|
736
1160
|
*/
|
|
737
1161
|
deleteRows(table: string, keys: Key[]): void;
|
|
738
1162
|
/**
|
|
@@ -745,6 +1169,7 @@ export declare class Transaction extends Dml {
|
|
|
745
1169
|
* into this table.
|
|
746
1170
|
*
|
|
747
1171
|
* @example
|
|
1172
|
+
* ```
|
|
748
1173
|
* const row = {
|
|
749
1174
|
* SingerId: 'Id3',
|
|
750
1175
|
* Name: 'Eddie Wilson'
|
|
@@ -767,7 +1192,9 @@ export declare class Transaction extends Dml {
|
|
|
767
1192
|
* });
|
|
768
1193
|
* });
|
|
769
1194
|
*
|
|
770
|
-
*
|
|
1195
|
+
* ```
|
|
1196
|
+
* @example Multiple rows can be inserted at once.
|
|
1197
|
+
* ```
|
|
771
1198
|
* const row2 = {
|
|
772
1199
|
* SingerId: 'Id3b',
|
|
773
1200
|
* Name: 'Joe West'
|
|
@@ -792,6 +1219,7 @@ export declare class Transaction extends Dml {
|
|
|
792
1219
|
* }
|
|
793
1220
|
* });
|
|
794
1221
|
* });
|
|
1222
|
+
* ```
|
|
795
1223
|
*/
|
|
796
1224
|
insert(table: string, rows: object | object[]): void;
|
|
797
1225
|
/**
|
|
@@ -804,6 +1232,7 @@ export declare class Transaction extends Dml {
|
|
|
804
1232
|
* into this table.
|
|
805
1233
|
*
|
|
806
1234
|
* @example
|
|
1235
|
+
* ```
|
|
807
1236
|
* const row = {
|
|
808
1237
|
* SingerId: 'Id3',
|
|
809
1238
|
* Name: 'Joe West'
|
|
@@ -825,8 +1254,40 @@ export declare class Transaction extends Dml {
|
|
|
825
1254
|
* }
|
|
826
1255
|
* });
|
|
827
1256
|
* });
|
|
1257
|
+
* ```
|
|
828
1258
|
*/
|
|
829
1259
|
replace(table: string, rows: object | object[]): void;
|
|
1260
|
+
/**
|
|
1261
|
+
* Roll back a transaction, releasing any locks it holds. It is a good idea to
|
|
1262
|
+
* call this for any transaction that includes one or more queries that you
|
|
1263
|
+
* decide not to commit.
|
|
1264
|
+
*
|
|
1265
|
+
* Wrapper around {@link v1.SpannerClient#rollback}.
|
|
1266
|
+
*
|
|
1267
|
+
* @see {@link v1.SpannerClient#rollback}
|
|
1268
|
+
* @see [Rollback API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.Rollback)
|
|
1269
|
+
*
|
|
1270
|
+
* @param {object} [gaxOptions] Request configuration options,
|
|
1271
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
1272
|
+
* for more details.
|
|
1273
|
+
* @param {BasicCallback} [callback] Callback function.
|
|
1274
|
+
* @returns {Promise<BasicResponse>}
|
|
1275
|
+
*
|
|
1276
|
+
* @example
|
|
1277
|
+
* ```
|
|
1278
|
+
* database.runTransaction(function(err, transaction) {
|
|
1279
|
+
* if (err) {
|
|
1280
|
+
* // Error handling omitted.
|
|
1281
|
+
* }
|
|
1282
|
+
*
|
|
1283
|
+
* transaction.rollback(function(err) {
|
|
1284
|
+
* if (!err) {
|
|
1285
|
+
* // Transaction rolled back successfully.
|
|
1286
|
+
* }
|
|
1287
|
+
* });
|
|
1288
|
+
* });
|
|
1289
|
+
* ```
|
|
1290
|
+
*/
|
|
830
1291
|
rollback(gaxOptions?: CallOptions): Promise<void>;
|
|
831
1292
|
rollback(callback: spannerClient.spanner.v1.Spanner.RollbackCallback): void;
|
|
832
1293
|
rollback(gaxOptions: CallOptions, callback: spannerClient.spanner.v1.Spanner.RollbackCallback): void;
|
|
@@ -840,6 +1301,7 @@ export declare class Transaction extends Dml {
|
|
|
840
1301
|
* into this table.
|
|
841
1302
|
*
|
|
842
1303
|
* @example
|
|
1304
|
+
* ```
|
|
843
1305
|
* const row = {
|
|
844
1306
|
* SingerId: 'Id3',
|
|
845
1307
|
* Name: 'Joe West'
|
|
@@ -861,6 +1323,7 @@ export declare class Transaction extends Dml {
|
|
|
861
1323
|
* }
|
|
862
1324
|
* });
|
|
863
1325
|
* });
|
|
1326
|
+
* ```
|
|
864
1327
|
*/
|
|
865
1328
|
update(table: string, rows: object | object[]): void;
|
|
866
1329
|
/**
|
|
@@ -873,6 +1336,7 @@ export declare class Transaction extends Dml {
|
|
|
873
1336
|
* into this table.
|
|
874
1337
|
*
|
|
875
1338
|
* @example
|
|
1339
|
+
* ```
|
|
876
1340
|
* const row = {
|
|
877
1341
|
* SingerId: 'Id3',
|
|
878
1342
|
* Name: 'Joe West'
|
|
@@ -894,6 +1358,7 @@ export declare class Transaction extends Dml {
|
|
|
894
1358
|
* }
|
|
895
1359
|
* });
|
|
896
1360
|
* });
|
|
1361
|
+
* ```
|
|
897
1362
|
*/
|
|
898
1363
|
upsert(table: string, rows: object | object[]): void;
|
|
899
1364
|
/**
|
|
@@ -934,6 +1399,31 @@ export declare class Transaction extends Dml {
|
|
|
934
1399
|
*/
|
|
935
1400
|
export declare class PartitionedDml extends Dml {
|
|
936
1401
|
constructor(session: Session, options?: spannerClient.spanner.v1.TransactionOptions.PartitionedDml);
|
|
1402
|
+
/**
|
|
1403
|
+
* Execute a DML statement and get the affected row count. Unlike
|
|
1404
|
+
* {@link Transaction#runUpdate} after using this method you should
|
|
1405
|
+
* immediately discard this transaction, internally it will invoke
|
|
1406
|
+
* {@link PartitionedDml#end}.
|
|
1407
|
+
*
|
|
1408
|
+
* @see Database#runPartitionedUpdate
|
|
1409
|
+
*
|
|
1410
|
+
* @param {string|object} query A DML statement or
|
|
1411
|
+
* [`ExecuteSqlRequest`](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ExecuteSqlRequest)
|
|
1412
|
+
* object.
|
|
1413
|
+
* @param {object} [query.params] A map of parameter name to values.
|
|
1414
|
+
* @param {object} [query.types] A map of parameter types.
|
|
1415
|
+
* @param {RunUpdateCallback} [callback] Callback function.
|
|
1416
|
+
* @returns {Promise<RunUpdateResponse>}
|
|
1417
|
+
*
|
|
1418
|
+
* @example
|
|
1419
|
+
* ```
|
|
1420
|
+
* transaction.runUpdate(query, (err, rowRount) => {
|
|
1421
|
+
* if (err) {
|
|
1422
|
+
* // Error handling omitted.
|
|
1423
|
+
* }
|
|
1424
|
+
* });
|
|
1425
|
+
* ```
|
|
1426
|
+
*/
|
|
937
1427
|
runUpdate(query: string | ExecuteSqlRequest): Promise<RunUpdateResponse>;
|
|
938
1428
|
runUpdate(query: string | ExecuteSqlRequest, callback: RunUpdateCallback): void;
|
|
939
1429
|
}
|