@google-cloud/spanner 7.18.0 → 7.18.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +1 -0
  3. package/build/protos/google/spanner/admin/database/v1/backup.proto +757 -0
  4. package/build/protos/google/spanner/admin/database/v1/backup_schedule.proto +230 -0
  5. package/build/protos/google/spanner/admin/database/v1/common.proto +132 -0
  6. package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +1209 -0
  7. package/build/protos/google/spanner/admin/instance/v1/common.proto +64 -0
  8. package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +2110 -0
  9. package/build/protos/google/spanner/executor/v1/cloud_executor.proto +1520 -0
  10. package/build/protos/google/spanner/v1/commit_response.proto +59 -0
  11. package/build/protos/google/spanner/v1/keys.proto +163 -0
  12. package/build/protos/google/spanner/v1/mutation.proto +107 -0
  13. package/build/protos/google/spanner/v1/query_plan.proto +128 -0
  14. package/build/protos/google/spanner/v1/result_set.proto +237 -0
  15. package/build/protos/google/spanner/v1/spanner.proto +1389 -0
  16. package/build/protos/google/spanner/v1/transaction.proto +575 -0
  17. package/build/protos/google/spanner/v1/type.proto +214 -0
  18. package/build/protos/protos.d.ts +39317 -0
  19. package/build/protos/protos.js +100360 -0
  20. package/build/protos/protos.json +10271 -0
  21. package/build/src/backup.d.ts +349 -0
  22. package/build/src/backup.js +246 -0
  23. package/build/src/batch-transaction.d.ts +247 -0
  24. package/build/src/batch-transaction.js +384 -0
  25. package/build/src/codec.d.ts +362 -0
  26. package/build/src/codec.js +791 -0
  27. package/build/src/common-grpc/service-object.d.ts +80 -0
  28. package/build/src/common-grpc/service-object.js +101 -0
  29. package/build/src/common-grpc/service.d.ts +445 -0
  30. package/build/src/common-grpc/service.js +826 -0
  31. package/build/src/common.d.ts +66 -0
  32. package/build/src/common.js +54 -0
  33. package/build/src/database.d.ts +2103 -0
  34. package/build/src/database.js +1655 -0
  35. package/build/src/extra_proto_list.json +1 -0
  36. package/build/src/helper.d.ts +45 -0
  37. package/build/src/helper.js +71 -0
  38. package/build/src/index.d.ts +1195 -0
  39. package/build/src/index.js +1059 -0
  40. package/build/src/instance-config.d.ts +294 -0
  41. package/build/src/instance-config.js +216 -0
  42. package/build/src/instance.d.ts +832 -0
  43. package/build/src/instance.js +781 -0
  44. package/build/src/instrument.d.ts +85 -0
  45. package/build/src/instrument.js +215 -0
  46. package/build/src/multiplexed-session.d.ts +136 -0
  47. package/build/src/multiplexed-session.js +197 -0
  48. package/build/src/partial-result-stream.d.ts +253 -0
  49. package/build/src/partial-result-stream.js +400 -0
  50. package/build/src/session-factory.d.ts +100 -0
  51. package/build/src/session-factory.js +93 -0
  52. package/build/src/session-pool.d.ts +471 -0
  53. package/build/src/session-pool.js +754 -0
  54. package/build/src/session.d.ts +258 -0
  55. package/build/src/session.js +348 -0
  56. package/build/src/spanner_grpc_config.json +92 -0
  57. package/build/src/table.d.ts +831 -0
  58. package/build/src/table.js +277 -0
  59. package/build/src/transaction-runner.d.ts +185 -0
  60. package/build/src/transaction-runner.js +282 -0
  61. package/build/src/transaction.d.ts +1691 -0
  62. package/build/src/transaction.js +2004 -0
  63. package/build/src/v1/database_admin_client.d.ts +2301 -0
  64. package/build/src/v1/database_admin_client.js +2286 -0
  65. package/build/src/v1/database_admin_client_config.json +160 -0
  66. package/build/src/v1/database_admin_proto_list.json +6 -0
  67. package/build/src/v1/gapic_metadata.json +27 -0
  68. package/build/src/v1/index.d.ts +4 -0
  69. package/build/src/v1/index.js +29 -0
  70. package/build/src/v1/instance_admin_client.d.ts +1985 -0
  71. package/build/src/v1/instance_admin_client.js +1768 -0
  72. package/build/src/v1/instance_admin_client_config.json +129 -0
  73. package/build/src/v1/instance_admin_proto_list.json +4 -0
  74. package/build/src/v1/spanner_client.d.ts +1250 -0
  75. package/build/src/v1/spanner_client.js +1086 -0
  76. package/build/src/v1/spanner_client_config.json +119 -0
  77. package/build/src/v1/spanner_executor_proxy_client.d.ts +418 -0
  78. package/build/src/v1/spanner_executor_proxy_client.js +706 -0
  79. package/build/src/v1/spanner_executor_proxy_client_config.json +30 -0
  80. package/build/src/v1/spanner_executor_proxy_proto_list.json +14 -0
  81. package/build/src/v1/spanner_proto_list.json +10 -0
  82. package/package.json +1 -1
@@ -0,0 +1,247 @@
1
+ /*!
2
+ * Copyright 2018 Google Inc. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Snapshot } from './transaction';
17
+ import { google } from '../protos/protos';
18
+ import { Session } from '.';
19
+ export interface TransactionIdentifier {
20
+ session: string | Session;
21
+ transaction?: string;
22
+ timestamp?: google.protobuf.ITimestamp;
23
+ }
24
+ /**
25
+ * Use a BatchTransaction object to create partitions and read/query against
26
+ * your Cloud Spanner database.
27
+ *
28
+ * @class
29
+ * @extends Snapshot
30
+ *
31
+ * @param {TimestampBounds} [options] [Timestamp Bounds](https://cloud.google.com/spanner/docs/timestamp-bounds).
32
+ */
33
+ declare class BatchTransaction extends Snapshot {
34
+ /**
35
+ * Closes all open resources.
36
+ *
37
+ * When the transaction is no longer needed, you should call this method to
38
+ * free up resources allocated by the Batch client.
39
+ *
40
+ * Calling this method would render the transaction unusable everywhere. In
41
+ * particular if this transaction object was being used across multiple
42
+ * machines, calling this method on any of the machine would make the
43
+ * transaction unusable on all the machines. This should only be called when
44
+ * the transaction is no longer needed anywhere
45
+ *
46
+ * @param {BasicCallback} [callback] Callback function.
47
+ * @returns {Promise<BasicResponse>}
48
+ *
49
+ * @example
50
+ * ```
51
+ * const {Spanner} = require('@google-cloud/spanner');
52
+ * const spanner = new Spanner();
53
+ *
54
+ * const instance = spanner.instance('my-instance');
55
+ * const database = instance.database('my-database');
56
+ *
57
+ * database.createBatchTransaction(function(err, transaction) {
58
+ * if (err) {
59
+ * // Error handling omitted.
60
+ * }
61
+ *
62
+ * transaction.close(function(err, apiResponse) {});
63
+ * });
64
+ *
65
+ * //-
66
+ * // If the callback is omitted, we'll return a Promise.
67
+ * //-
68
+ * database.createBatchTransaction().then(function(data) {
69
+ * const transaction = data[0];
70
+ * return transaction.close();
71
+ * });
72
+ * ```
73
+ */
74
+ close(callback?: any): void;
75
+ /**
76
+ * @see [`ExecuteSqlRequest`](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ExecuteSqlRequest)
77
+ * @typedef {object} QueryPartition
78
+ * @property {string} partitionToken The partition token.
79
+ */
80
+ /**
81
+ * @typedef {array} CreateQueryPartitionsResponse
82
+ * @property {QueryPartition[]} 0 List of query partitions.
83
+ * @property {object} 1 The full API response.
84
+ */
85
+ /**
86
+ * @callback CreateQueryPartitionsCallback
87
+ * @param {?Error} err Request error, if any.
88
+ * @param {QueryPartition[]} partitions List of query partitions.
89
+ * @param {object} apiResponse The full API response.
90
+ */
91
+ /**
92
+ * Creates a set of query partitions that can be used to execute a query
93
+ * operation in parallel. Partitions become invalid when the transaction used
94
+ * to create them is closed.
95
+ *
96
+ * @param {string|object} query A SQL query or
97
+ * [`ExecuteSqlRequest`](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ExecuteSqlRequest)
98
+ * object.
99
+ * @param {object} [query.gaxOptions] Request configuration options,
100
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
101
+ * for more details.
102
+ * @param {object} [query.params] A map of parameter name to values.
103
+ * @param {object} [query.partitionOptions] A map of partition options.
104
+ * @param {object} [query.types] A map of parameter types.
105
+ * @param {CreateQueryPartitionsCallback} [callback] Callback callback function.
106
+ * @returns {Promise<CreateQueryPartitionsResponse>}
107
+ *
108
+ * @example <caption>include:samples/batch.js</caption>
109
+ * region_tag:spanner_batch_client
110
+ */
111
+ createQueryPartitions(query: any, callback: any): void;
112
+ protected getDBName(): string;
113
+ /**
114
+ * Generic create partition method. Handles common parameters used in both
115
+ * {@link BatchTransaction#createQueryPartitions} and {@link
116
+ * BatchTransaction#createReadPartitions}
117
+ *
118
+ * @private
119
+ *
120
+ * @param {object} config The request config.
121
+ * @param {function} callback Callback function.
122
+ */
123
+ createPartitions_(config: any, callback: any): void;
124
+ /**
125
+ * @typedef {object} ReadPartition
126
+ * @mixes ReadRequestOptions
127
+ * @property {string} partitionToken The partition token.
128
+ * @property {object} [gaxOptions] Request configuration options,
129
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
130
+ * for more details.
131
+ */
132
+ /**
133
+ * @typedef {array} CreateReadPartitionsResponse
134
+ * @property {ReadPartition[]} 0 List of read partitions.
135
+ * @property {object} 1 The full API response.
136
+ */
137
+ /**
138
+ * @callback CreateReadPartitionsCallback
139
+ * @param {?Error} err Request error, if any.
140
+ * @param {ReadPartition[]} partitions List of read partitions.
141
+ * @param {object} apiResponse The full API response.
142
+ */
143
+ /**
144
+ * Creates a set of read partitions that can be used to execute a read
145
+ * operation in parallel. Partitions become invalid when the transaction used
146
+ * to create them is closed.
147
+ *
148
+ * @param {ReadRequestOptions} options Configuration object, describing what to
149
+ * read from.
150
+ * @param {CreateReadPartitionsCallback} [callback] Callback function.
151
+ * @returns {Promise<CreateReadPartitionsResponse>}
152
+ */
153
+ createReadPartitions(options: any, callback: any): void;
154
+ /**
155
+ * Executes partition.
156
+ *
157
+ * @see {@link Transaction#read} when using {@link ReadPartition}.
158
+ * @see {@link Transaction#run} when using {@link QueryParition}.
159
+ *
160
+ * @param {ReadPartition|QueryParition} partition The partition object.
161
+ * @param {object} [partition.gaxOptions] Request configuration options,
162
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
163
+ * for more details.
164
+ * @param {TransactionRequestReadCallback|RunCallback} [callback] Callback
165
+ * function.
166
+ * @returns {Promise<RunResponse>|Promise<TransactionRequestReadResponse>}
167
+ *
168
+ * @example <caption>include:samples/batch.js</caption>
169
+ * region_tag:spanner_batch_execute_partitions
170
+ */
171
+ execute(partition: any, callback: any): void;
172
+ /**
173
+ * Executes partition in streaming mode.
174
+ *
175
+ * @see {@link Transaction#createReadStream} when using {@link ReadPartition}.
176
+ * @see {@link Transaction#runStream} when using {@link QueryPartition}.
177
+ *
178
+ * @param {ReadPartition|QueryPartition} partition The partition object.
179
+ * @returns {ReadableStream} A readable stream that emits rows.
180
+ *
181
+ * @example
182
+ * ```
183
+ * const {Spanner} = require('@google-cloud/spanner');
184
+ * const spanner = new Spanner();
185
+ *
186
+ * const instance = spanner.instance('my-instance');
187
+ * const database = instance.database('my-database');
188
+ *
189
+ * database.createBatchTransaction(function(err, transaction) {
190
+ * if (err) {
191
+ * // Error handling omitted.
192
+ * }
193
+ *
194
+ * transaction.createReadPartitions(options, function(err, partitions) {
195
+ * const partition = partitions[0];
196
+ *
197
+ * transaction
198
+ * .executeStream(partition)
199
+ * .on('error', function(err) {})
200
+ * .on('data', function(row) {
201
+ * // row = [
202
+ * // {
203
+ * // name: 'SingerId',
204
+ * // value: '1'
205
+ * // },
206
+ * // {
207
+ * // name: 'Name',
208
+ * // value: 'Eddie Wilson'
209
+ * // }
210
+ * // ]
211
+ * })
212
+ * .on('end', function() {
213
+ * // All results retrieved
214
+ * });
215
+ * });
216
+ * });
217
+ * ```
218
+ */
219
+ executeStream(partition: any): import("./partial-result-stream").PartialResultStream;
220
+ /**
221
+ * @typedef {object} TransactionIdentifier
222
+ * @property {string|Session} session The full session name.
223
+ * @property {string} transaction The transaction ID.
224
+ * @property {string|Date} readTimestamp The transaction read timestamp.
225
+ */
226
+ /**
227
+ * Creates a transaction identifier used to reference the transaction in
228
+ * workers.
229
+ *
230
+ * @returns {TransactionIdentifier}
231
+ *
232
+ * @example
233
+ * ```
234
+ * const {Spanner} = require('@google-cloud/spanner');
235
+ * const spanner = new Spanner();
236
+ *
237
+ * const instance = spanner.instance('my-instance');
238
+ * const database = instance.database('my-database');
239
+ *
240
+ * database.createBatchTransaction(function(err, transaction) {
241
+ * const identifier = transaction.identifier();
242
+ * });
243
+ * ```
244
+ */
245
+ identifier(): TransactionIdentifier;
246
+ }
247
+ export { BatchTransaction };
@@ -0,0 +1,384 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright 2018 Google Inc. All Rights Reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.BatchTransaction = void 0;
19
+ const precise_date_1 = require("@google-cloud/precise-date");
20
+ const promisify_1 = require("@google-cloud/promisify");
21
+ const extend = require("extend");
22
+ const is = require("is");
23
+ const transaction_1 = require("./transaction");
24
+ const common_1 = require("../src/common");
25
+ const instrument_1 = require("./instrument");
26
+ /**
27
+ * Use a BatchTransaction object to create partitions and read/query against
28
+ * your Cloud Spanner database.
29
+ *
30
+ * @class
31
+ * @extends Snapshot
32
+ *
33
+ * @param {TimestampBounds} [options] [Timestamp Bounds](https://cloud.google.com/spanner/docs/timestamp-bounds).
34
+ */
35
+ class BatchTransaction extends transaction_1.Snapshot {
36
+ /**
37
+ * Closes all open resources.
38
+ *
39
+ * When the transaction is no longer needed, you should call this method to
40
+ * free up resources allocated by the Batch client.
41
+ *
42
+ * Calling this method would render the transaction unusable everywhere. In
43
+ * particular if this transaction object was being used across multiple
44
+ * machines, calling this method on any of the machine would make the
45
+ * transaction unusable on all the machines. This should only be called when
46
+ * the transaction is no longer needed anywhere
47
+ *
48
+ * @param {BasicCallback} [callback] Callback function.
49
+ * @returns {Promise<BasicResponse>}
50
+ *
51
+ * @example
52
+ * ```
53
+ * const {Spanner} = require('@google-cloud/spanner');
54
+ * const spanner = new Spanner();
55
+ *
56
+ * const instance = spanner.instance('my-instance');
57
+ * const database = instance.database('my-database');
58
+ *
59
+ * database.createBatchTransaction(function(err, transaction) {
60
+ * if (err) {
61
+ * // Error handling omitted.
62
+ * }
63
+ *
64
+ * transaction.close(function(err, apiResponse) {});
65
+ * });
66
+ *
67
+ * //-
68
+ * // If the callback is omitted, we'll return a Promise.
69
+ * //-
70
+ * database.createBatchTransaction().then(function(data) {
71
+ * const transaction = data[0];
72
+ * return transaction.close();
73
+ * });
74
+ * ```
75
+ */
76
+ close(callback) {
77
+ this.end();
78
+ if (callback) {
79
+ callback();
80
+ }
81
+ }
82
+ /**
83
+ * @see [`ExecuteSqlRequest`](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ExecuteSqlRequest)
84
+ * @typedef {object} QueryPartition
85
+ * @property {string} partitionToken The partition token.
86
+ */
87
+ /**
88
+ * @typedef {array} CreateQueryPartitionsResponse
89
+ * @property {QueryPartition[]} 0 List of query partitions.
90
+ * @property {object} 1 The full API response.
91
+ */
92
+ /**
93
+ * @callback CreateQueryPartitionsCallback
94
+ * @param {?Error} err Request error, if any.
95
+ * @param {QueryPartition[]} partitions List of query partitions.
96
+ * @param {object} apiResponse The full API response.
97
+ */
98
+ /**
99
+ * Creates a set of query partitions that can be used to execute a query
100
+ * operation in parallel. Partitions become invalid when the transaction used
101
+ * to create them is closed.
102
+ *
103
+ * @param {string|object} query A SQL query or
104
+ * [`ExecuteSqlRequest`](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ExecuteSqlRequest)
105
+ * object.
106
+ * @param {object} [query.gaxOptions] Request configuration options,
107
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
108
+ * for more details.
109
+ * @param {object} [query.params] A map of parameter name to values.
110
+ * @param {object} [query.partitionOptions] A map of partition options.
111
+ * @param {object} [query.types] A map of parameter types.
112
+ * @param {CreateQueryPartitionsCallback} [callback] Callback callback function.
113
+ * @returns {Promise<CreateQueryPartitionsResponse>}
114
+ *
115
+ * @example <caption>include:samples/batch.js</caption>
116
+ * region_tag:spanner_batch_client
117
+ */
118
+ createQueryPartitions(query, callback) {
119
+ if (is.string(query)) {
120
+ query = {
121
+ sql: query,
122
+ };
123
+ }
124
+ const reqOpts = Object.assign({}, query, transaction_1.Snapshot.encodeParams(query));
125
+ delete reqOpts.gaxOptions;
126
+ delete reqOpts.types;
127
+ const traceConfig = {
128
+ sql: query,
129
+ opts: this._observabilityOptions,
130
+ dbName: this.getDBName(),
131
+ };
132
+ return (0, instrument_1.startTrace)('BatchTransaction.createQueryPartitions', traceConfig, span => {
133
+ const headers = {};
134
+ if (this._getSpanner().routeToLeaderEnabled) {
135
+ (0, common_1.addLeaderAwareRoutingHeader)(headers);
136
+ }
137
+ this.createPartitions_({
138
+ client: 'SpannerClient',
139
+ method: 'partitionQuery',
140
+ reqOpts,
141
+ gaxOpts: query.gaxOptions,
142
+ headers: headers,
143
+ }, (err, partitions, resp) => {
144
+ if (err) {
145
+ (0, instrument_1.setSpanError)(span, err);
146
+ }
147
+ span.end();
148
+ callback(err, partitions, resp);
149
+ });
150
+ });
151
+ }
152
+ getDBName() {
153
+ return this.session.parent.formattedName_;
154
+ }
155
+ /**
156
+ * Generic create partition method. Handles common parameters used in both
157
+ * {@link BatchTransaction#createQueryPartitions} and {@link
158
+ * BatchTransaction#createReadPartitions}
159
+ *
160
+ * @private
161
+ *
162
+ * @param {object} config The request config.
163
+ * @param {function} callback Callback function.
164
+ */
165
+ createPartitions_(config, callback) {
166
+ const traceConfig = {
167
+ opts: this._observabilityOptions,
168
+ dbName: this.getDBName(),
169
+ };
170
+ return (0, instrument_1.startTrace)('BatchTransaction.createPartitions_', traceConfig, span => {
171
+ const query = extend({}, config.reqOpts, {
172
+ session: this.session.formattedName_,
173
+ transaction: { id: this.id },
174
+ });
175
+ config.reqOpts = extend({}, query);
176
+ config.headers = {
177
+ [common_1.CLOUD_RESOURCE_HEADER]: this.session.parent
178
+ .formattedName_,
179
+ };
180
+ delete query.partitionOptions;
181
+ this.session.request(config, (err, resp) => {
182
+ if (err) {
183
+ (0, instrument_1.setSpanError)(span, err);
184
+ span.end();
185
+ callback(err, null, resp);
186
+ return;
187
+ }
188
+ const partitions = resp.partitions.map(partition => {
189
+ return extend({}, query, partition);
190
+ });
191
+ if (resp.transaction) {
192
+ const { id, readTimestamp } = resp.transaction;
193
+ this.id = id;
194
+ if (readTimestamp) {
195
+ this.readTimestampProto = readTimestamp;
196
+ this.readTimestamp = new precise_date_1.PreciseDate(readTimestamp);
197
+ }
198
+ }
199
+ span.end();
200
+ callback(null, partitions, resp);
201
+ });
202
+ });
203
+ }
204
+ /**
205
+ * @typedef {object} ReadPartition
206
+ * @mixes ReadRequestOptions
207
+ * @property {string} partitionToken The partition token.
208
+ * @property {object} [gaxOptions] Request configuration options,
209
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
210
+ * for more details.
211
+ */
212
+ /**
213
+ * @typedef {array} CreateReadPartitionsResponse
214
+ * @property {ReadPartition[]} 0 List of read partitions.
215
+ * @property {object} 1 The full API response.
216
+ */
217
+ /**
218
+ * @callback CreateReadPartitionsCallback
219
+ * @param {?Error} err Request error, if any.
220
+ * @param {ReadPartition[]} partitions List of read partitions.
221
+ * @param {object} apiResponse The full API response.
222
+ */
223
+ /**
224
+ * Creates a set of read partitions that can be used to execute a read
225
+ * operation in parallel. Partitions become invalid when the transaction used
226
+ * to create them is closed.
227
+ *
228
+ * @param {ReadRequestOptions} options Configuration object, describing what to
229
+ * read from.
230
+ * @param {CreateReadPartitionsCallback} [callback] Callback function.
231
+ * @returns {Promise<CreateReadPartitionsResponse>}
232
+ */
233
+ createReadPartitions(options, callback) {
234
+ const traceConfig = {
235
+ opts: this._observabilityOptions,
236
+ dbName: this.getDBName(),
237
+ };
238
+ return (0, instrument_1.startTrace)('BatchTransaction.createReadPartitions', traceConfig, span => {
239
+ const reqOpts = Object.assign({}, options, {
240
+ keySet: transaction_1.Snapshot.encodeKeySet(options),
241
+ });
242
+ delete reqOpts.gaxOptions;
243
+ delete reqOpts.keys;
244
+ delete reqOpts.ranges;
245
+ const headers = {};
246
+ if (this._getSpanner().routeToLeaderEnabled) {
247
+ (0, common_1.addLeaderAwareRoutingHeader)(headers);
248
+ }
249
+ this.createPartitions_({
250
+ client: 'SpannerClient',
251
+ method: 'partitionRead',
252
+ reqOpts,
253
+ gaxOpts: options.gaxOptions,
254
+ headers: headers,
255
+ }, (err, partitions, resp) => {
256
+ if (err) {
257
+ (0, instrument_1.setSpanError)(span, err);
258
+ }
259
+ span.end();
260
+ callback(err, partitions, resp);
261
+ });
262
+ });
263
+ }
264
+ /**
265
+ * Executes partition.
266
+ *
267
+ * @see {@link Transaction#read} when using {@link ReadPartition}.
268
+ * @see {@link Transaction#run} when using {@link QueryParition}.
269
+ *
270
+ * @param {ReadPartition|QueryParition} partition The partition object.
271
+ * @param {object} [partition.gaxOptions] Request configuration options,
272
+ * See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
273
+ * for more details.
274
+ * @param {TransactionRequestReadCallback|RunCallback} [callback] Callback
275
+ * function.
276
+ * @returns {Promise<RunResponse>|Promise<TransactionRequestReadResponse>}
277
+ *
278
+ * @example <caption>include:samples/batch.js</caption>
279
+ * region_tag:spanner_batch_execute_partitions
280
+ */
281
+ execute(partition, callback) {
282
+ if (is.string(partition.table)) {
283
+ this.read(partition.table, partition, callback);
284
+ return;
285
+ }
286
+ this.run(partition, callback);
287
+ }
288
+ /**
289
+ * Executes partition in streaming mode.
290
+ *
291
+ * @see {@link Transaction#createReadStream} when using {@link ReadPartition}.
292
+ * @see {@link Transaction#runStream} when using {@link QueryPartition}.
293
+ *
294
+ * @param {ReadPartition|QueryPartition} partition The partition object.
295
+ * @returns {ReadableStream} A readable stream that emits rows.
296
+ *
297
+ * @example
298
+ * ```
299
+ * const {Spanner} = require('@google-cloud/spanner');
300
+ * const spanner = new Spanner();
301
+ *
302
+ * const instance = spanner.instance('my-instance');
303
+ * const database = instance.database('my-database');
304
+ *
305
+ * database.createBatchTransaction(function(err, transaction) {
306
+ * if (err) {
307
+ * // Error handling omitted.
308
+ * }
309
+ *
310
+ * transaction.createReadPartitions(options, function(err, partitions) {
311
+ * const partition = partitions[0];
312
+ *
313
+ * transaction
314
+ * .executeStream(partition)
315
+ * .on('error', function(err) {})
316
+ * .on('data', function(row) {
317
+ * // row = [
318
+ * // {
319
+ * // name: 'SingerId',
320
+ * // value: '1'
321
+ * // },
322
+ * // {
323
+ * // name: 'Name',
324
+ * // value: 'Eddie Wilson'
325
+ * // }
326
+ * // ]
327
+ * })
328
+ * .on('end', function() {
329
+ * // All results retrieved
330
+ * });
331
+ * });
332
+ * });
333
+ * ```
334
+ */
335
+ executeStream(partition) {
336
+ // TODO: Instrument the streams with Otel.
337
+ if (is.string(partition.table)) {
338
+ return this.createReadStream(partition.table, partition);
339
+ }
340
+ return this.runStream(partition);
341
+ }
342
+ /**
343
+ * @typedef {object} TransactionIdentifier
344
+ * @property {string|Session} session The full session name.
345
+ * @property {string} transaction The transaction ID.
346
+ * @property {string|Date} readTimestamp The transaction read timestamp.
347
+ */
348
+ /**
349
+ * Creates a transaction identifier used to reference the transaction in
350
+ * workers.
351
+ *
352
+ * @returns {TransactionIdentifier}
353
+ *
354
+ * @example
355
+ * ```
356
+ * const {Spanner} = require('@google-cloud/spanner');
357
+ * const spanner = new Spanner();
358
+ *
359
+ * const instance = spanner.instance('my-instance');
360
+ * const database = instance.database('my-database');
361
+ *
362
+ * database.createBatchTransaction(function(err, transaction) {
363
+ * const identifier = transaction.identifier();
364
+ * });
365
+ * ```
366
+ */
367
+ identifier() {
368
+ return {
369
+ transaction: this.id.toString('base64'),
370
+ session: this.session.id,
371
+ timestamp: this.readTimestampProto,
372
+ };
373
+ }
374
+ }
375
+ exports.BatchTransaction = BatchTransaction;
376
+ /*! Developer Documentation
377
+ *
378
+ * All async methods (except for streams) will return a Promise in the event
379
+ * that a callback is omitted.
380
+ */
381
+ (0, promisify_1.promisifyAll)(BatchTransaction, {
382
+ exclude: ['identifier'],
383
+ });
384
+ //# sourceMappingURL=batch-transaction.js.map