@google-cloud/spanner 5.15.0 → 5.16.1
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 +55 -53
- package/build/protos/protos.d.ts +2 -1
- package/build/protos/protos.js +7 -0
- 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/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 +3 -3
package/build/src/table.d.ts
CHANGED
|
@@ -53,17 +53,73 @@ export declare type UpsertRowsOptions = MutateRowsOptions;
|
|
|
53
53
|
* @param {string} name Name of the table.
|
|
54
54
|
*
|
|
55
55
|
* @example
|
|
56
|
+
* ```
|
|
56
57
|
* const {Spanner} = require('@google-cloud/spanner');
|
|
57
58
|
* const spanner = new Spanner();
|
|
58
59
|
*
|
|
59
60
|
* const instance = spanner.instance('my-instance');
|
|
60
61
|
* const database = instance.database('my-database');
|
|
61
62
|
* const table = database.table('my-table');
|
|
63
|
+
* ```
|
|
62
64
|
*/
|
|
63
65
|
declare class Table {
|
|
64
66
|
database: Database;
|
|
65
67
|
name: string;
|
|
66
68
|
constructor(database: Database, name: string);
|
|
69
|
+
/**
|
|
70
|
+
* Create a table.
|
|
71
|
+
*
|
|
72
|
+
* @param {string} schema See {@link Database#createTable}.
|
|
73
|
+
* @param {object} [gaxOptions]
|
|
74
|
+
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
75
|
+
* for more details.
|
|
76
|
+
* @param {CreateTableCallback} [callback] Callback function.
|
|
77
|
+
* @returns {Promise<CreateTableResponse>}
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```
|
|
81
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
82
|
+
* const spanner = new Spanner();
|
|
83
|
+
*
|
|
84
|
+
* const instance = spanner.instance('my-instance');
|
|
85
|
+
* const database = instance.database('my-database');
|
|
86
|
+
* const table = database.table('Singers');
|
|
87
|
+
*
|
|
88
|
+
* const schema =
|
|
89
|
+
* 'CREATE TABLE Singers (' +
|
|
90
|
+
* ' SingerId INT64 NOT NULL,' +
|
|
91
|
+
* ' FirstName STRING(1024),' +
|
|
92
|
+
* ' LastName STRING(1024),' +
|
|
93
|
+
* ' SingerInfo BYTES(MAX),' +
|
|
94
|
+
* ') PRIMARY KEY(SingerId)';
|
|
95
|
+
*
|
|
96
|
+
* table.create(schema, function(err, table, operation, apiResponse) {
|
|
97
|
+
* if (err) {
|
|
98
|
+
* // Error handling omitted.
|
|
99
|
+
* }
|
|
100
|
+
*
|
|
101
|
+
* operation
|
|
102
|
+
* .on('error', function(err) {})
|
|
103
|
+
* .on('complete', function() {
|
|
104
|
+
* // Table created successfully.
|
|
105
|
+
* });
|
|
106
|
+
* });
|
|
107
|
+
*
|
|
108
|
+
* //-
|
|
109
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
110
|
+
* //-
|
|
111
|
+
* table.create(schema)
|
|
112
|
+
* .then(function(data) {
|
|
113
|
+
* const table = data[0];
|
|
114
|
+
* const operation = data[1];
|
|
115
|
+
*
|
|
116
|
+
* return operation.promise();
|
|
117
|
+
* })
|
|
118
|
+
* .then(function() {
|
|
119
|
+
* // Table created successfully.
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
67
123
|
create(schema: Schema, gaxOptions?: CallOptions): Promise<CreateTableResponse>;
|
|
68
124
|
create(schema: Schema, callback: CreateTableCallback): void;
|
|
69
125
|
create(schema: Schema, gaxOptions: CallOptions, callback: CreateTableCallback): void;
|
|
@@ -79,6 +135,7 @@ declare class Table {
|
|
|
79
135
|
* @returns {PartialResultStream} A readable stream that emits rows.
|
|
80
136
|
*
|
|
81
137
|
* @example
|
|
138
|
+
* ```
|
|
82
139
|
* const {Spanner} = require('@google-cloud/spanner');
|
|
83
140
|
* const spanner = new Spanner();
|
|
84
141
|
*
|
|
@@ -129,29 +186,617 @@ declare class Table {
|
|
|
129
186
|
* .on('data', function(row) {
|
|
130
187
|
* this.end();
|
|
131
188
|
* });
|
|
189
|
+
* ```
|
|
132
190
|
*/
|
|
133
191
|
createReadStream(request: ReadRequest, options?: TimestampBounds): PartialResultStream;
|
|
192
|
+
/**
|
|
193
|
+
* @typedef {array} DropTableResponse
|
|
194
|
+
* @property {google.longrunning.Operation} 0 An {@link Operation} object that can be used to check
|
|
195
|
+
* the status of the request.
|
|
196
|
+
* @property {object} 1 The full API response.
|
|
197
|
+
*/
|
|
198
|
+
/**
|
|
199
|
+
* @callback DropTableCallback
|
|
200
|
+
* @param {?Error} err Request error, if any.
|
|
201
|
+
* @param {google.longrunning.Operation} operation An {@link Operation} object that can be used to
|
|
202
|
+
* check the status of the request.
|
|
203
|
+
* @param {object} apiResponse The full API response.
|
|
204
|
+
*/
|
|
205
|
+
/**
|
|
206
|
+
* Delete the table. Not to be confused with {@link Table#deleteRows}.
|
|
207
|
+
*
|
|
208
|
+
* Wrapper around {@link Database#updateSchema}.
|
|
209
|
+
*
|
|
210
|
+
* @see {@link Database#updateSchema}
|
|
211
|
+
*
|
|
212
|
+
* @throws {TypeError} If any arguments are passed in.
|
|
213
|
+
* @param {object} [gaxOptions]
|
|
214
|
+
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
215
|
+
* for more details.
|
|
216
|
+
* @param {DropTableCallback} [callback] Callback function.
|
|
217
|
+
* @returns {Promise<DropTableResponse>}
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```
|
|
221
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
222
|
+
* const spanner = new Spanner();
|
|
223
|
+
*
|
|
224
|
+
* const instance = spanner.instance('my-instance');
|
|
225
|
+
* const database = instance.database('my-database');
|
|
226
|
+
* const table = database.table('Singers');
|
|
227
|
+
*
|
|
228
|
+
* table.delete(function(err, operation, apiResponse) {
|
|
229
|
+
* if (err) {
|
|
230
|
+
* // Error handling omitted.
|
|
231
|
+
* }
|
|
232
|
+
*
|
|
233
|
+
* operation
|
|
234
|
+
* .on('error', function(err) {})
|
|
235
|
+
* .on('complete', function() {
|
|
236
|
+
* // Table deleted successfully.
|
|
237
|
+
* });
|
|
238
|
+
* });
|
|
239
|
+
*
|
|
240
|
+
* //-
|
|
241
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
242
|
+
* //-
|
|
243
|
+
* table.delete()
|
|
244
|
+
* .then(function(data) {
|
|
245
|
+
* const operation = data[0];
|
|
246
|
+
* return operation.promise();
|
|
247
|
+
* })
|
|
248
|
+
* .then(function() {
|
|
249
|
+
* // Table deleted successfully.
|
|
250
|
+
* });
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
134
253
|
delete(gaxOptions?: CallOptions): Promise<DropTableResponse>;
|
|
135
254
|
delete(callback: DropTableCallback): void;
|
|
136
255
|
delete(gaxOptions: CallOptions, callback: DropTableCallback): void;
|
|
256
|
+
/**
|
|
257
|
+
* @typedef {array} DeleteRowsResponse
|
|
258
|
+
* @property {CommitResponse} 0 The commit response.
|
|
259
|
+
*/
|
|
260
|
+
/**
|
|
261
|
+
* @callback DeleteRowsCallback
|
|
262
|
+
* @param {?Error} error Request error, if any.
|
|
263
|
+
* @param {CommitResponse} apiResponse The full API response.
|
|
264
|
+
*/
|
|
265
|
+
/**
|
|
266
|
+
* @typedef {object} DeleteRowsOptions
|
|
267
|
+
* @property {google.spanner.v1.IRequestOptions} requestOptions The request options to include
|
|
268
|
+
* with the commit request.
|
|
269
|
+
* @property {boolean} returnCommitStats Include statistics related to the
|
|
270
|
+
* transaction in the {@link CommitResponse}.
|
|
271
|
+
* @property {object} [gaxOptions]
|
|
272
|
+
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
273
|
+
* for more details.
|
|
274
|
+
*/
|
|
275
|
+
/**
|
|
276
|
+
* Delete rows from this table.
|
|
277
|
+
*
|
|
278
|
+
* @see [Commit API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.Commit)
|
|
279
|
+
*
|
|
280
|
+
* @param {array} keys The keys for the rows to delete. If using a
|
|
281
|
+
* composite key, provide an array within this array. See the example
|
|
282
|
+
* below.
|
|
283
|
+
* @param {DeleteRowsOptions|CallOptions} [options] Options for configuring the request.
|
|
284
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
285
|
+
* for more details.
|
|
286
|
+
* @param {DeleteRowsCallback} [callback] Callback function.
|
|
287
|
+
* @returns {Promise<DeleteRowsResponse>}
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```
|
|
291
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
292
|
+
* const spanner = new Spanner();
|
|
293
|
+
*
|
|
294
|
+
* const instance = spanner.instance('my-instance');
|
|
295
|
+
* const database = instance.database('my-database');
|
|
296
|
+
* const table = database.table('Singers');
|
|
297
|
+
*
|
|
298
|
+
* const keys = ['Id1', 'Id2', 'Id3'];
|
|
299
|
+
*
|
|
300
|
+
* table.deleteRows(keys, function(err, apiResponse) {});
|
|
301
|
+
*
|
|
302
|
+
* //-
|
|
303
|
+
* // Provide an array for `keys` to delete rows with a composite key.
|
|
304
|
+
* //-
|
|
305
|
+
* const keys = [
|
|
306
|
+
* [
|
|
307
|
+
* 'Id1',
|
|
308
|
+
* 'Name1'
|
|
309
|
+
* ],
|
|
310
|
+
* [
|
|
311
|
+
* 'Id2',
|
|
312
|
+
* 'Name2'
|
|
313
|
+
* ]
|
|
314
|
+
* ];
|
|
315
|
+
*
|
|
316
|
+
* //-
|
|
317
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
318
|
+
* //-
|
|
319
|
+
* table.deleteRows(keys)
|
|
320
|
+
* .then(function(data) {
|
|
321
|
+
* const apiResponse = data[0];
|
|
322
|
+
* });
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
137
325
|
deleteRows(keys: Key[], options?: DeleteRowsOptions | CallOptions): Promise<DeleteRowsResponse>;
|
|
138
326
|
deleteRows(keys: Key[], callback: DeleteRowsCallback): void;
|
|
139
327
|
deleteRows(keys: Key[], options: DeleteRowsOptions | CallOptions, callback: DeleteRowsCallback): void;
|
|
328
|
+
/**
|
|
329
|
+
* Drop the table.
|
|
330
|
+
*
|
|
331
|
+
* @see {@link Table#delete}
|
|
332
|
+
* @see {@link Database#updateSchema}
|
|
333
|
+
*
|
|
334
|
+
* @param {object} [gaxOptions] Request configuration options.
|
|
335
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
336
|
+
* for more details.
|
|
337
|
+
* @param {DropTableCallback} [callback] Callback function.
|
|
338
|
+
* @returns {Promise<DropTableResponse>}
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```
|
|
342
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
343
|
+
* const spanner = new Spanner();
|
|
344
|
+
*
|
|
345
|
+
* const instance = spanner.instance('my-instance');
|
|
346
|
+
* const database = instance.database('my-database');
|
|
347
|
+
* const table = database.table('Singers');
|
|
348
|
+
*
|
|
349
|
+
* table.drop(function(err, operation, apiResponse) {
|
|
350
|
+
* if (err) {
|
|
351
|
+
* // Error handling omitted.
|
|
352
|
+
* }
|
|
353
|
+
*
|
|
354
|
+
* operation
|
|
355
|
+
* .on('error', function(err) {})
|
|
356
|
+
* .on('complete', function() {
|
|
357
|
+
* // Table dropped successfully.
|
|
358
|
+
* });
|
|
359
|
+
* });
|
|
360
|
+
*
|
|
361
|
+
* //-
|
|
362
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
363
|
+
* //-
|
|
364
|
+
* table.drop()
|
|
365
|
+
* .then(function(data) {
|
|
366
|
+
* const operation = data[0];
|
|
367
|
+
* return operation.promise();
|
|
368
|
+
* })
|
|
369
|
+
* .then(function() {
|
|
370
|
+
* // Table dropped successfully.
|
|
371
|
+
* });
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
140
374
|
drop(gaxOptions?: CallOptions): Promise<DropTableResponse>;
|
|
141
375
|
drop(callback: DropTableCallback): void;
|
|
142
376
|
drop(gaxOptions: CallOptions, callback: DropTableCallback): void;
|
|
377
|
+
/**
|
|
378
|
+
* @typedef {array} InsertRowsResponse
|
|
379
|
+
* @property {CommitResponse} 0 The commit response.
|
|
380
|
+
*/
|
|
381
|
+
/**
|
|
382
|
+
* @callback InsertRowsCallback
|
|
383
|
+
* @param {?Error} error Request error, if any.
|
|
384
|
+
* @param {CommitResponse} apiResponse The full API response.
|
|
385
|
+
*/
|
|
386
|
+
/**
|
|
387
|
+
* @typedef {object} InsertRowsOptions
|
|
388
|
+
* @property {google.spanner.v1.IRequestOptions} requestOptions The request options to include
|
|
389
|
+
* with the commit request.
|
|
390
|
+
* @property {boolean} returnCommitStats Include statistics related to the
|
|
391
|
+
* transaction in the {@link CommitResponse}.
|
|
392
|
+
* @property {object} [gaxOptions]
|
|
393
|
+
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
394
|
+
* for more details.
|
|
395
|
+
*/
|
|
396
|
+
/**
|
|
397
|
+
* Insert rows of data into this table.
|
|
398
|
+
*
|
|
399
|
+
* @see [Commit API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.Commit)
|
|
400
|
+
*
|
|
401
|
+
* @param {object|object[]} rows A map of names to values of data to insert
|
|
402
|
+
* into this table.
|
|
403
|
+
* @param {InsertRowsOptions|CallOptions} [options] Options for configuring the request.
|
|
404
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
405
|
+
* for more details.
|
|
406
|
+
* @param {InsertRowsCallback} [callback] Callback function.
|
|
407
|
+
* @returns {Promise<InsertRowsResponse>}
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```
|
|
411
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
412
|
+
* const spanner = new Spanner();
|
|
413
|
+
*
|
|
414
|
+
* const instance = spanner.instance('my-instance');
|
|
415
|
+
* const database = instance.database('my-database');
|
|
416
|
+
* const table = database.table('Singers');
|
|
417
|
+
*
|
|
418
|
+
* const row = {
|
|
419
|
+
* SingerId: 'Id3',
|
|
420
|
+
* Name: 'Eddie Wilson'
|
|
421
|
+
* };
|
|
422
|
+
*
|
|
423
|
+
* table.insert(row, function(err, apiResponse) {
|
|
424
|
+
* if (err) {
|
|
425
|
+
* // Error handling omitted.
|
|
426
|
+
* }
|
|
427
|
+
*
|
|
428
|
+
* // Rows inserted successfully.
|
|
429
|
+
* });
|
|
430
|
+
*
|
|
431
|
+
* //-
|
|
432
|
+
* // Multiple rows can be inserted at once.
|
|
433
|
+
* //-
|
|
434
|
+
* const row2 = {
|
|
435
|
+
* SingerId: 'Id3b',
|
|
436
|
+
* Name: 'Joe West'
|
|
437
|
+
* };
|
|
438
|
+
*
|
|
439
|
+
* table.insert([
|
|
440
|
+
* row,
|
|
441
|
+
* row2
|
|
442
|
+
* ], function(err, apiResponse) {});
|
|
443
|
+
*
|
|
444
|
+
* //-
|
|
445
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
446
|
+
* //-
|
|
447
|
+
* table.insert(row)
|
|
448
|
+
* .then(function(data) {
|
|
449
|
+
* const apiResponse = data[0];
|
|
450
|
+
* });
|
|
451
|
+
*
|
|
452
|
+
* ```
|
|
453
|
+
* @example <caption>include:samples/crud.js</caption>
|
|
454
|
+
* region_tag:spanner_insert_data
|
|
455
|
+
* Full example:
|
|
456
|
+
*/
|
|
143
457
|
insert(rows: object | object[], options?: InsertRowsOptions | CallOptions): Promise<InsertRowsResponse>;
|
|
144
458
|
insert(rows: object | object[], callback: InsertRowsCallback): void;
|
|
145
459
|
insert(rows: object | object[], options: InsertRowsOptions | CallOptions, callback: InsertRowsCallback): void;
|
|
460
|
+
/**
|
|
461
|
+
* Configuration object, describing what to read from the table.
|
|
462
|
+
*/
|
|
463
|
+
/**
|
|
464
|
+
* @typedef {array} TableReadResponse
|
|
465
|
+
* @property {array[]} 0 Rows are returned as an array of object arrays. Each
|
|
466
|
+
* object has a `name` and `value` property. To get a serialized object,
|
|
467
|
+
* call `toJSON()`. Optionally, provide an options object to `toJSON()`
|
|
468
|
+
* specifying `wrapNumbers: true` to protect large integer values outside
|
|
469
|
+
* of the range of JavaScript Number. If set, FLOAT64 values will be returned
|
|
470
|
+
* as {@link Spanner.Float} objects and INT64 values as {@link
|
|
471
|
+
* Spanner.Int}.
|
|
472
|
+
*/
|
|
473
|
+
/**
|
|
474
|
+
* @callback TableReadCallback
|
|
475
|
+
* @param {?Error} err Request error, if any.
|
|
476
|
+
* @param {array[]} rows Rows are returned as an array of object arrays. Each
|
|
477
|
+
* object has a `name` and `value` property. To get a serialized object,
|
|
478
|
+
* call `toJSON()`. Optionally, provide an options object to `toJSON()`
|
|
479
|
+
* specifying `wrapNumbers: true` to protect large integer values outside
|
|
480
|
+
* of the range of JavaScript Number. If set, FLOAT64 values will be returned
|
|
481
|
+
* as {@link Spanner.Float} objects and INT64 values as {@link
|
|
482
|
+
* Spanner.Int}.
|
|
483
|
+
*/
|
|
484
|
+
/**
|
|
485
|
+
* Receive rows from the database using key lookups and scans.
|
|
486
|
+
*
|
|
487
|
+
* **Performance Considerations:**
|
|
488
|
+
*
|
|
489
|
+
* This method wraps the streaming method,
|
|
490
|
+
* {@link Table#createReadStream} for your convenience. All rows will
|
|
491
|
+
* be stored in memory before being released to your callback. If you intend
|
|
492
|
+
* on receiving a lot of results from your query, consider using the streaming
|
|
493
|
+
* method, so you can free each result from memory after consuming it.
|
|
494
|
+
*
|
|
495
|
+
* @param {ReadRequest} query Configuration object, describing
|
|
496
|
+
* what to read from the table.
|
|
497
|
+
* @param {TimestampBounds} options [Transaction options](https://cloud.google.com/spanner/docs/timestamp-bounds).
|
|
498
|
+
* @param {TableReadCallback} [callback] Callback function.
|
|
499
|
+
* @returns {Promise<TableReadResponse>}
|
|
500
|
+
*
|
|
501
|
+
* @example
|
|
502
|
+
* ```
|
|
503
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
504
|
+
* const spanner = new Spanner();
|
|
505
|
+
*
|
|
506
|
+
* const instance = spanner.instance('my-instance');
|
|
507
|
+
* const database = instance.database('my-database');
|
|
508
|
+
* const table = database.table('Singers');
|
|
509
|
+
*
|
|
510
|
+
* const query = {
|
|
511
|
+
* keys: ['1'],
|
|
512
|
+
* columns: ['SingerId', 'name']
|
|
513
|
+
* };
|
|
514
|
+
*
|
|
515
|
+
* table.read(query, function(err, rows) {
|
|
516
|
+
* if (err) {
|
|
517
|
+
* // Error handling omitted.
|
|
518
|
+
* }
|
|
519
|
+
*
|
|
520
|
+
* const firstRow = rows[0];
|
|
521
|
+
*
|
|
522
|
+
* // firstRow = [
|
|
523
|
+
* // {
|
|
524
|
+
* // name: 'SingerId',
|
|
525
|
+
* // value: '1'
|
|
526
|
+
* // },
|
|
527
|
+
* // {
|
|
528
|
+
* // name: 'Name',
|
|
529
|
+
* // value: 'Eddie Wilson'
|
|
530
|
+
* // }
|
|
531
|
+
* // ]
|
|
532
|
+
* });
|
|
533
|
+
*
|
|
534
|
+
* //-
|
|
535
|
+
* // Provide an array for `query.keys` to read with a composite key.
|
|
536
|
+
* //-
|
|
537
|
+
* const query = {
|
|
538
|
+
* keys: [
|
|
539
|
+
* [
|
|
540
|
+
* 'Id1',
|
|
541
|
+
* 'Name1'
|
|
542
|
+
* ],
|
|
543
|
+
* [
|
|
544
|
+
* 'Id2',
|
|
545
|
+
* 'Name2'
|
|
546
|
+
* ]
|
|
547
|
+
* ],
|
|
548
|
+
* // ...
|
|
549
|
+
* };
|
|
550
|
+
*
|
|
551
|
+
* //-
|
|
552
|
+
* // Rows are returned as an array of object arrays. Each object has a `name`
|
|
553
|
+
* // and `value` property. To get a serialized object, call `toJSON()`.
|
|
554
|
+
* //
|
|
555
|
+
* // Alternatively, set `query.json` to `true`, and this step will be
|
|
556
|
+
* performed
|
|
557
|
+
* // automatically.
|
|
558
|
+
* //-
|
|
559
|
+
* table.read(query, function(err, rows) {
|
|
560
|
+
* if (err) {
|
|
561
|
+
* // Error handling omitted.
|
|
562
|
+
* }
|
|
563
|
+
*
|
|
564
|
+
* const firstRow = rows[0];
|
|
565
|
+
*
|
|
566
|
+
* // firstRow.toJSON() = {
|
|
567
|
+
* // SingerId: '1',
|
|
568
|
+
* // Name: 'Eddie Wilson'
|
|
569
|
+
* // }
|
|
570
|
+
* });
|
|
571
|
+
*
|
|
572
|
+
* //-
|
|
573
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
574
|
+
* //-
|
|
575
|
+
* table.read(query)
|
|
576
|
+
* .then(function(data) {
|
|
577
|
+
* const rows = data[0];
|
|
578
|
+
* });
|
|
579
|
+
*
|
|
580
|
+
* ```
|
|
581
|
+
* @example <caption>include:samples/crud.js</caption>
|
|
582
|
+
* region_tag:spanner_read_data
|
|
583
|
+
* Full example:
|
|
584
|
+
*
|
|
585
|
+
* @example <caption>include:samples/crud.js</caption>
|
|
586
|
+
* region_tag:spanner_read_stale_data
|
|
587
|
+
* Reading stale data:
|
|
588
|
+
*
|
|
589
|
+
* @example <caption>include:samples/index-read-data.js</caption>
|
|
590
|
+
* region_tag:spanner_read_data_with_index
|
|
591
|
+
* Reading data using an index:
|
|
592
|
+
*
|
|
593
|
+
* @example <caption>include:samples/index-read-data-with-storing.js</caption>
|
|
594
|
+
* region_tag:spanner_read_data_with_storing_index
|
|
595
|
+
* Reading data using a storing index:
|
|
596
|
+
*/
|
|
146
597
|
read(request: ReadRequest, options?: TimestampBounds): Promise<ReadResponse>;
|
|
147
598
|
read(request: ReadRequest, callback: ReadCallback): void;
|
|
148
599
|
read(request: ReadRequest, options: TimestampBounds, callback: ReadCallback): void;
|
|
600
|
+
/**
|
|
601
|
+
* @typedef {array} ReplaceRowsResponse
|
|
602
|
+
* @property {CommitResponse} 0 The commit response.
|
|
603
|
+
*/
|
|
604
|
+
/**
|
|
605
|
+
* @callback ReplaceRowsCallback
|
|
606
|
+
* @param {?Error} error Request error, if any.
|
|
607
|
+
* @param {CommitResponse} apiResponse The full API response.
|
|
608
|
+
*/
|
|
609
|
+
/**
|
|
610
|
+
* @typedef {object} ReplaceRowsOptions
|
|
611
|
+
* @property {google.spanner.v1.IRequestOptions} requestOptions The request options to include
|
|
612
|
+
* with the commit request.
|
|
613
|
+
* @property {boolean} returnCommitStats Include statistics related to the
|
|
614
|
+
* transaction in the {@link CommitResponse}.
|
|
615
|
+
* @property {object} [gaxOptions]
|
|
616
|
+
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
617
|
+
* for more details.
|
|
618
|
+
*/
|
|
619
|
+
/**
|
|
620
|
+
* Replace rows of data within this table.
|
|
621
|
+
*
|
|
622
|
+
* @see [Commit API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.Commit)
|
|
623
|
+
*
|
|
624
|
+
* @param {object|object[]} rows A map of names to values of data to insert
|
|
625
|
+
* into this table.
|
|
626
|
+
* @param {ReplaceRowsOptions|CallOptions} [options] Options for configuring the request.
|
|
627
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
628
|
+
* for more details.
|
|
629
|
+
* @param {ReplaceRowsCallback} [callback] Callback function.
|
|
630
|
+
* @returns {Promise<ReplaceRowsResponse>}
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```
|
|
634
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
635
|
+
* const spanner = new Spanner();
|
|
636
|
+
*
|
|
637
|
+
* const instance = spanner.instance('my-instance');
|
|
638
|
+
* const database = instance.database('my-database');
|
|
639
|
+
* const table = database.table('Singers');
|
|
640
|
+
*
|
|
641
|
+
* const row = {
|
|
642
|
+
* SingerId: 'Id3',
|
|
643
|
+
* Name: 'Joe West'
|
|
644
|
+
* };
|
|
645
|
+
*
|
|
646
|
+
* table.replace(row, function(err, apiResponse) {
|
|
647
|
+
* if (err) {
|
|
648
|
+
* // Error handling omitted.
|
|
649
|
+
* }
|
|
650
|
+
*
|
|
651
|
+
* // Row replaced successfully.
|
|
652
|
+
* });
|
|
653
|
+
*
|
|
654
|
+
* //-
|
|
655
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
656
|
+
* //-
|
|
657
|
+
* table.replace(row)
|
|
658
|
+
* .then(function(data) {
|
|
659
|
+
* const apiResponse = data[0];
|
|
660
|
+
* });
|
|
661
|
+
* ```
|
|
662
|
+
*/
|
|
149
663
|
replace(rows: object | object[], options?: ReplaceRowsOptions | CallOptions): Promise<ReplaceRowsResponse>;
|
|
150
664
|
replace(rows: object | object[], callback: ReplaceRowsCallback): void;
|
|
151
665
|
replace(rows: object | object[], options: ReplaceRowsOptions | CallOptions, callback: ReplaceRowsCallback): void;
|
|
666
|
+
/**
|
|
667
|
+
* @typedef {array} UpdateRowsResponse
|
|
668
|
+
* @property {CommitResponse} 0 The commit response.
|
|
669
|
+
*/
|
|
670
|
+
/**
|
|
671
|
+
* @callback UpdateRowsCallback
|
|
672
|
+
* @param {?Error} error Request error, if any.
|
|
673
|
+
* @param {CommitResponse} apiResponse The full API response.
|
|
674
|
+
*/
|
|
675
|
+
/**
|
|
676
|
+
* @typedef {object} UpdateRowsOptions
|
|
677
|
+
* @property {google.spanner.v1.IRequestOptions} requestOptions The request options to include
|
|
678
|
+
* with the commit request.
|
|
679
|
+
* @property {boolean} returnCommitStats Include statistics related to the
|
|
680
|
+
* transaction in the {@link CommitResponse}.
|
|
681
|
+
* @property {object} [gaxOptions]
|
|
682
|
+
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
683
|
+
* for more details.
|
|
684
|
+
*/
|
|
685
|
+
/**
|
|
686
|
+
* Update rows of data within this table.
|
|
687
|
+
*
|
|
688
|
+
* @see [Commit API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.Commit)
|
|
689
|
+
*
|
|
690
|
+
* @param {object|object[]} rows A map of names to values of data to insert
|
|
691
|
+
* into this table.
|
|
692
|
+
* @param {UpdateRowsOptions|CallOptions} [options] Options for configuring the request.
|
|
693
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
694
|
+
* for more details.
|
|
695
|
+
* @param {UpdateRowsCallback} [callback] Callback function.
|
|
696
|
+
* @returns {Promise<UpdateRowsResponse>}
|
|
697
|
+
*
|
|
698
|
+
* @example
|
|
699
|
+
* ```
|
|
700
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
701
|
+
* const spanner = new Spanner();
|
|
702
|
+
*
|
|
703
|
+
* const instance = spanner.instance('my-instance');
|
|
704
|
+
* const database = instance.database('my-database');
|
|
705
|
+
* const table = database.table('Singers');
|
|
706
|
+
*
|
|
707
|
+
* const row = {
|
|
708
|
+
* SingerId: 'Id3',
|
|
709
|
+
* Name: 'Joe West'
|
|
710
|
+
* };
|
|
711
|
+
*
|
|
712
|
+
* table.update(row, function(err, apiResponse) {
|
|
713
|
+
* if (err) {
|
|
714
|
+
* // Error handling omitted.
|
|
715
|
+
* }
|
|
716
|
+
*
|
|
717
|
+
* // Row updated successfully.
|
|
718
|
+
* });
|
|
719
|
+
*
|
|
720
|
+
* //-
|
|
721
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
722
|
+
* //-
|
|
723
|
+
* table.update(row)
|
|
724
|
+
* .then(function(data) {
|
|
725
|
+
* const apiResponse = data[0];
|
|
726
|
+
* });
|
|
727
|
+
*
|
|
728
|
+
* ```
|
|
729
|
+
* @example <caption>include:samples/crud.js</caption>
|
|
730
|
+
* region_tag:spanner_update_data
|
|
731
|
+
* Full example:
|
|
732
|
+
*/
|
|
152
733
|
update(rows: object | object[], options?: UpdateRowsOptions | CallOptions): Promise<UpdateRowsResponse>;
|
|
153
734
|
update(rows: object | object[], callback: UpdateRowsCallback): void;
|
|
154
735
|
update(rows: object | object[], options: UpdateRowsOptions | CallOptions, callback: UpdateRowsCallback): void;
|
|
736
|
+
/**
|
|
737
|
+
* @typedef {array} UpsertRowsResponse
|
|
738
|
+
* @property {CommitResponse} 0 The commit response.
|
|
739
|
+
*/
|
|
740
|
+
/**
|
|
741
|
+
* @callback UpsertRowsCallback
|
|
742
|
+
* @param {?Error} error Request error, if any.
|
|
743
|
+
* @param {CommitResponse} apiResponse The full API response.
|
|
744
|
+
*/
|
|
745
|
+
/**
|
|
746
|
+
* @typedef {object} UpsertRowsOptions
|
|
747
|
+
* @property {google.spanner.v1.IRequestOptions} requestOptions The request options to include
|
|
748
|
+
* with the commit request.
|
|
749
|
+
* @property {boolean} returnCommitStats Include statistics related to the
|
|
750
|
+
* transaction in the {@link CommitResponse}.
|
|
751
|
+
* @property {object} [gaxOptions]
|
|
752
|
+
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
753
|
+
* for more details.
|
|
754
|
+
*/
|
|
755
|
+
/**
|
|
756
|
+
* Insert or update rows of data within this table.
|
|
757
|
+
*
|
|
758
|
+
* @see [Commit API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.Commit)
|
|
759
|
+
*
|
|
760
|
+
* @param {object|object[]} rows A map of names to values of data to insert
|
|
761
|
+
* into this table.
|
|
762
|
+
*
|
|
763
|
+
* @param {UpsertRowsOptions|CallOptions} [options] Options for configuring the request.
|
|
764
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
765
|
+
* for more details.
|
|
766
|
+
* @param {UpsertRowsCallback} [callback] Callback function.
|
|
767
|
+
* @returns {Promise<UpsertRowsResponse>}
|
|
768
|
+
*
|
|
769
|
+
* @example
|
|
770
|
+
* ```
|
|
771
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
772
|
+
* const spanner = new Spanner();
|
|
773
|
+
*
|
|
774
|
+
* const instance = spanner.instance('my-instance');
|
|
775
|
+
* const database = instance.database('my-database');
|
|
776
|
+
* const table = database.table('Singers');
|
|
777
|
+
*
|
|
778
|
+
* const row = {
|
|
779
|
+
* SingerId: 'Id3',
|
|
780
|
+
* Name: 'Joe West'
|
|
781
|
+
* };
|
|
782
|
+
*
|
|
783
|
+
* table.upsert(row, function(err, apiResponse) {
|
|
784
|
+
* if (err) {
|
|
785
|
+
* // Error handling omitted.
|
|
786
|
+
* }
|
|
787
|
+
*
|
|
788
|
+
* // Row inserted or updated successfully.
|
|
789
|
+
* });
|
|
790
|
+
*
|
|
791
|
+
* //-
|
|
792
|
+
* // If the callback is omitted, we'll return a Promise.
|
|
793
|
+
* //-
|
|
794
|
+
* table.upsert(row)
|
|
795
|
+
* .then(function(data) {
|
|
796
|
+
* const apiResponse = data[0];
|
|
797
|
+
* });
|
|
798
|
+
* ```
|
|
799
|
+
*/
|
|
155
800
|
upsert(rows: object | object[], options?: UpsertRowsOptions | CallOptions): Promise<UpsertRowsResponse>;
|
|
156
801
|
upsert(rows: object | object[], callback: UpsertRowsCallback): void;
|
|
157
802
|
upsert(rows: object | object[], options: UpsertRowsOptions | CallOptions, callback: UpsertRowsCallback): void;
|