@google-cloud/spanner 9.0.0 → 9.1.0
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/README.md +1 -16
- package/build/src/batch-transaction.js +15 -12
- package/build/src/codec.d.ts +6 -0
- package/build/src/codec.js +99 -34
- package/build/src/common.d.ts +14 -0
- package/build/src/common.js +27 -1
- package/build/src/database.d.ts +31 -41
- package/build/src/database.js +122 -313
- package/build/src/helper.d.ts +12 -0
- package/build/src/helper.js +44 -0
- package/build/src/index.d.ts +16 -8
- package/build/src/index.js +210 -90
- package/build/src/instance.d.ts +15 -2
- package/build/src/instance.js +11 -2
- package/build/src/instrument.d.ts +12 -1
- package/build/src/instrument.js +13 -0
- package/build/src/metrics/constants.d.ts +6 -0
- package/build/src/metrics/constants.js +6 -1
- package/build/src/metrics/interceptor.js +32 -28
- package/build/src/metrics/metrics-tracer-factory.d.ts +6 -11
- package/build/src/metrics/metrics-tracer-factory.js +62 -64
- package/build/src/metrics/metrics-tracer.d.ts +19 -6
- package/build/src/metrics/metrics-tracer.js +147 -55
- package/build/src/multiplexed-session.d.ts +13 -2
- package/build/src/multiplexed-session.js +20 -4
- package/build/src/partial-result-stream.d.ts +26 -33
- package/build/src/partial-result-stream.js +263 -283
- package/build/src/request-stream-coordinator.d.ts +88 -0
- package/build/src/request-stream-coordinator.js +229 -0
- package/build/src/request_id_header.d.ts +6 -4
- package/build/src/request_id_header.js +24 -24
- package/build/src/session-factory.d.ts +52 -63
- package/build/src/session-factory.js +41 -92
- package/build/src/session-pool.d.ts +97 -227
- package/build/src/session-pool.js +74 -547
- package/build/src/session.js +1 -1
- package/build/src/transaction-runner.js +1 -12
- package/build/src/transaction.d.ts +5 -5
- package/build/src/transaction.js +72 -112
- package/package.json +9 -10
package/README.md
CHANGED
|
@@ -104,26 +104,11 @@ Refer to the Observability README to know more about tracing support in the Clou
|
|
|
104
104
|
|
|
105
105
|
## Multiplexed Sessions
|
|
106
106
|
|
|
107
|
-
Spanner's Multiplexed Sessions is
|
|
107
|
+
Spanner's Multiplexed Sessions is the default and only session mode in the Node.js client. This feature helps reduce
|
|
108
108
|
session management overhead and minimize session-related errors.
|
|
109
109
|
|
|
110
110
|
For a detailed explanation on multiplexed sessions, please refer to the [official documentation](https://cloud.google.com/spanner/docs/sessions#multiplexed_sessions).
|
|
111
111
|
|
|
112
|
-
## Regular Sessions
|
|
113
|
-
|
|
114
|
-
To use regular sessions, disable the multiplexed sessions and set the following environment variables to `false`:
|
|
115
|
-
|
|
116
|
-
* **For Read-Only Transactions:**
|
|
117
|
-
- `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS`
|
|
118
|
-
* **For Partitioned Operations:**
|
|
119
|
-
- `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS`
|
|
120
|
-
- `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS`
|
|
121
|
-
* **For Read-Write Transactions:**
|
|
122
|
-
- `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS`
|
|
123
|
-
- `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW`
|
|
124
|
-
|
|
125
|
-
For a detailed explanation on session modes and env configurations, please refer to the [official documentation](https://cloud.google.com/spanner/docs/sessions).
|
|
126
|
-
|
|
127
112
|
|
|
128
113
|
## Samples
|
|
129
114
|
|
|
@@ -81,13 +81,14 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
81
81
|
}
|
|
82
82
|
createQueryPartitions(query, cb) {
|
|
83
83
|
const request = typeof query === 'string' ? { sql: query } : query;
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
const { gaxOptions: _omittedGaxOptions, types: _omittedTypes, ...cleanRequest } = request;
|
|
85
|
+
void _omittedGaxOptions;
|
|
86
|
+
void _omittedTypes;
|
|
87
|
+
const reqOpts = Object.assign({}, cleanRequest, transaction_1.Snapshot.encodeParams(request));
|
|
87
88
|
const traceConfig = {
|
|
88
|
-
sql: request.sql,
|
|
89
89
|
opts: this._observabilityOptions,
|
|
90
90
|
dbName: this.getDBName(),
|
|
91
|
+
...(0, instrument_1.getQueryTraceConfig)(query),
|
|
91
92
|
};
|
|
92
93
|
return (0, instrument_1.startTrace)('BatchTransaction.createQueryPartitions', traceConfig, span => {
|
|
93
94
|
const headers = {};
|
|
@@ -128,17 +129,18 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
128
129
|
dbName: this.getDBName(),
|
|
129
130
|
};
|
|
130
131
|
return (0, instrument_1.startTrace)('BatchTransaction.createPartitions_', traceConfig, span => {
|
|
131
|
-
const
|
|
132
|
+
const baseRequest = Object.assign({}, config.reqOpts, {
|
|
132
133
|
session: this.session.formattedName_,
|
|
133
134
|
transaction: { id: this.id },
|
|
134
135
|
});
|
|
135
|
-
config.reqOpts =
|
|
136
|
+
config.reqOpts = baseRequest;
|
|
136
137
|
const headers = {
|
|
137
138
|
[common_1.CLOUD_RESOURCE_HEADER]: this.session.parent
|
|
138
139
|
.formattedName_,
|
|
139
140
|
};
|
|
140
141
|
config.headers = (0, request_id_header_1.injectRequestIDIntoHeaders)(headers, this.session);
|
|
141
|
-
|
|
142
|
+
const { partitionOptions: _omittedPartitionOptions, ...baseRequestWithoutPartitionOptions } = baseRequest;
|
|
143
|
+
void _omittedPartitionOptions;
|
|
142
144
|
this.session.request(config, (err, resp) => {
|
|
143
145
|
if (err) {
|
|
144
146
|
(0, instrument_1.setSpanError)(span, err);
|
|
@@ -147,7 +149,7 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
147
149
|
return;
|
|
148
150
|
}
|
|
149
151
|
const partitions = resp.partitions.map(partition => {
|
|
150
|
-
return Object.assign({},
|
|
152
|
+
return Object.assign({}, baseRequestWithoutPartitionOptions, partition);
|
|
151
153
|
});
|
|
152
154
|
if (resp.transaction) {
|
|
153
155
|
const { id, readTimestamp } = resp.transaction;
|
|
@@ -168,12 +170,13 @@ class BatchTransaction extends transaction_1.Snapshot {
|
|
|
168
170
|
dbName: this.getDBName(),
|
|
169
171
|
};
|
|
170
172
|
return (0, instrument_1.startTrace)('BatchTransaction.createReadPartitions', traceConfig, span => {
|
|
171
|
-
const
|
|
173
|
+
const { gaxOptions: _omittedGaxOptions, keys: _omittedKeys, ranges: _omittedRanges, ...cleanOptions } = options;
|
|
174
|
+
void _omittedGaxOptions;
|
|
175
|
+
void _omittedKeys;
|
|
176
|
+
void _omittedRanges;
|
|
177
|
+
const reqOpts = Object.assign({}, cleanOptions, {
|
|
172
178
|
keySet: transaction_1.Snapshot.encodeKeySet(options),
|
|
173
179
|
});
|
|
174
|
-
delete reqOpts.gaxOptions;
|
|
175
|
-
delete reqOpts.keys;
|
|
176
|
-
delete reqOpts.ranges;
|
|
177
180
|
const headers = {};
|
|
178
181
|
if (this._getSpanner().routeToLeaderEnabled) {
|
|
179
182
|
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
package/build/src/codec.d.ts
CHANGED
|
@@ -317,6 +317,12 @@ declare function decode(value: Value, type: spannerClient.spanner.v1.Type, colum
|
|
|
317
317
|
/**
|
|
318
318
|
* Encode a value in the format the API expects.
|
|
319
319
|
*
|
|
320
|
+
* This emits the `google.protobuf.Value` shape in a single pass: values are
|
|
321
|
+
* normalized and wrapped in their protobuf kind at the same time, so neither an
|
|
322
|
+
* intermediate representation nor a per-value `ObjectToStructConverter` is
|
|
323
|
+
* allocated. The branches prioritize primitive and common types for fast
|
|
324
|
+
* dispatch in hot query execution paths.
|
|
325
|
+
*
|
|
320
326
|
* @private
|
|
321
327
|
*
|
|
322
328
|
* @param {*} value The value to be encoded.
|
package/build/src/codec.js
CHANGED
|
@@ -17,7 +17,6 @@ exports.getDecoder = getDecoder;
|
|
|
17
17
|
* See the License for the specific language governing permissions and
|
|
18
18
|
* limitations under the License.
|
|
19
19
|
*/
|
|
20
|
-
const service_1 = require("./common-grpc/service");
|
|
21
20
|
const precise_date_1 = require("@google-cloud/precise-date");
|
|
22
21
|
const helper_1 = require("./helper");
|
|
23
22
|
const big_js_1 = require("big.js");
|
|
@@ -1010,65 +1009,131 @@ function parsePreciseDate(isoString) {
|
|
|
1010
1009
|
/**
|
|
1011
1010
|
* Encode a value in the format the API expects.
|
|
1012
1011
|
*
|
|
1012
|
+
* This emits the `google.protobuf.Value` shape in a single pass: values are
|
|
1013
|
+
* normalized and wrapped in their protobuf kind at the same time, so neither an
|
|
1014
|
+
* intermediate representation nor a per-value `ObjectToStructConverter` is
|
|
1015
|
+
* allocated. The branches prioritize primitive and common types for fast
|
|
1016
|
+
* dispatch in hot query execution paths.
|
|
1017
|
+
*
|
|
1013
1018
|
* @private
|
|
1014
1019
|
*
|
|
1015
1020
|
* @param {*} value The value to be encoded.
|
|
1016
1021
|
* @returns {object} google.protobuf.Value
|
|
1017
1022
|
*/
|
|
1018
1023
|
function encode(value) {
|
|
1019
|
-
|
|
1024
|
+
switch (typeof value) {
|
|
1025
|
+
case 'string':
|
|
1026
|
+
return { stringValue: value };
|
|
1027
|
+
case 'number':
|
|
1028
|
+
// Only non-integer, finite numbers are sent as a protobuf number. Every
|
|
1029
|
+
// other numeric value — integers (INT64 is a string on the wire) as well
|
|
1030
|
+
// as NaN and ±Infinity — is sent as a string.
|
|
1031
|
+
return Number.isFinite(value) && !Number.isInteger(value)
|
|
1032
|
+
? { numberValue: value }
|
|
1033
|
+
: { stringValue: value.toString() };
|
|
1034
|
+
case 'boolean':
|
|
1035
|
+
return { boolValue: value };
|
|
1036
|
+
case 'object':
|
|
1037
|
+
return value === null ? { nullValue: 0 } : encodeObject(value);
|
|
1038
|
+
default:
|
|
1039
|
+
throw new Error(`Value of type ${typeof value} not recognized.`);
|
|
1040
|
+
}
|
|
1020
1041
|
}
|
|
1021
1042
|
/**
|
|
1022
|
-
*
|
|
1023
|
-
* conversion to a google.protobuf.Value object happens via
|
|
1024
|
-
* `Service.encodeValue_`
|
|
1043
|
+
* Encodes a non-null object into a google.protobuf.Value.
|
|
1025
1044
|
*
|
|
1026
1045
|
* @private
|
|
1027
1046
|
*
|
|
1028
|
-
* @param {
|
|
1029
|
-
* @returns {
|
|
1047
|
+
* @param {object} value The value to be encoded.
|
|
1048
|
+
* @returns {object} google.protobuf.Value
|
|
1030
1049
|
*/
|
|
1031
|
-
function
|
|
1032
|
-
if (
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
return value.toJSON();
|
|
1050
|
+
function encodeObject(value) {
|
|
1051
|
+
if (value instanceof Date) {
|
|
1052
|
+
// `Date.prototype.toJSON` returns null for invalid dates.
|
|
1053
|
+
const json = value.toJSON();
|
|
1054
|
+
return json === null ? { nullValue: 0 } : { stringValue: json };
|
|
1037
1055
|
}
|
|
1038
1056
|
if (value instanceof WrappedNumber) {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
if (value instanceof Numeric) {
|
|
1042
|
-
return value.value;
|
|
1057
|
+
// `Float`/`Float32` hold a number, `Int`/`PGOid` hold a string.
|
|
1058
|
+
return encodeNumberOrString(value.value);
|
|
1043
1059
|
}
|
|
1044
|
-
if (value
|
|
1045
|
-
return value
|
|
1060
|
+
if (Array.isArray(value)) {
|
|
1061
|
+
return { listValue: { values: encodeArrayValues(value) } };
|
|
1046
1062
|
}
|
|
1047
1063
|
if (Buffer.isBuffer(value)) {
|
|
1048
|
-
return value.toString('base64');
|
|
1064
|
+
return { stringValue: value.toString('base64') };
|
|
1049
1065
|
}
|
|
1050
|
-
if (value instanceof
|
|
1051
|
-
return value.value
|
|
1066
|
+
if (value instanceof Numeric || value instanceof PGNumeric) {
|
|
1067
|
+
return { stringValue: value.value };
|
|
1052
1068
|
}
|
|
1053
|
-
if (value instanceof
|
|
1054
|
-
return value.
|
|
1069
|
+
if (value instanceof Interval) {
|
|
1070
|
+
return { stringValue: value.toISO8601() };
|
|
1055
1071
|
}
|
|
1056
|
-
if (value instanceof
|
|
1057
|
-
return
|
|
1072
|
+
if (value instanceof ProtoMessage) {
|
|
1073
|
+
return { stringValue: value.value.toString('base64') };
|
|
1058
1074
|
}
|
|
1059
|
-
if (
|
|
1060
|
-
|
|
1075
|
+
if (value instanceof ProtoEnum) {
|
|
1076
|
+
// Holds either the numeric constant or its string representation.
|
|
1077
|
+
return encodeNumberOrString(value.value);
|
|
1061
1078
|
}
|
|
1062
1079
|
if (value instanceof PGJsonb) {
|
|
1063
|
-
return value.toString();
|
|
1064
|
-
}
|
|
1065
|
-
if (value instanceof Interval) {
|
|
1066
|
-
return value.toISO8601();
|
|
1080
|
+
return { stringValue: value.toString() };
|
|
1067
1081
|
}
|
|
1068
1082
|
if ((0, helper_1.isObject)(value)) {
|
|
1069
|
-
|
|
1083
|
+
const json = JSON.stringify(value);
|
|
1084
|
+
// `JSON.stringify` returns undefined only when an object's `toJSON()`
|
|
1085
|
+
// method returns undefined. Other objects without a JSON representation
|
|
1086
|
+
// (such as Functions, Symbols, and Maps) fail `isObject` and throw below.
|
|
1087
|
+
// Note: `JSON.stringify` will throw a TypeError for circular structures
|
|
1088
|
+
// or BigInt property values.
|
|
1089
|
+
if (json !== undefined) {
|
|
1090
|
+
return { stringValue: json };
|
|
1091
|
+
}
|
|
1070
1092
|
}
|
|
1071
|
-
|
|
1093
|
+
if (value instanceof Number ||
|
|
1094
|
+
value instanceof String ||
|
|
1095
|
+
value instanceof Boolean) {
|
|
1096
|
+
// Boxed primitives are never produced by the public API, but were accepted
|
|
1097
|
+
// by the previous implementation.
|
|
1098
|
+
return encode(value.valueOf());
|
|
1099
|
+
}
|
|
1100
|
+
if ((0, helper_1.isDate)(value)) {
|
|
1101
|
+
// A `Date` from another realm (e.g. a `vm` context) fails `instanceof`.
|
|
1102
|
+
const json = value.toJSON();
|
|
1103
|
+
return json === null ? { nullValue: 0 } : { stringValue: json };
|
|
1104
|
+
}
|
|
1105
|
+
throw new Error('Value of type object not recognized.');
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Encodes the members of an array — or the field values of a {@link Struct},
|
|
1109
|
+
* which is itself an array — into google.protobuf.Value messages.
|
|
1110
|
+
*
|
|
1111
|
+
* @private
|
|
1112
|
+
*
|
|
1113
|
+
* @param {Array} value The array to be encoded.
|
|
1114
|
+
* @returns {object[]} google.protobuf.Value[]
|
|
1115
|
+
*/
|
|
1116
|
+
function encodeArrayValues(value) {
|
|
1117
|
+
const { length } = value;
|
|
1118
|
+
const values = new Array(length);
|
|
1119
|
+
const isStruct = value instanceof Struct;
|
|
1120
|
+
for (let i = 0; i < length; i++) {
|
|
1121
|
+
values[i] = encode(isStruct ? value[i].value : value[i]);
|
|
1122
|
+
}
|
|
1123
|
+
return values;
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* Wraps an already normalized value in the matching google.protobuf.Value kind.
|
|
1127
|
+
*
|
|
1128
|
+
* @private
|
|
1129
|
+
*
|
|
1130
|
+
* @param {string|number} value The value to be wrapped.
|
|
1131
|
+
* @returns {object} google.protobuf.Value
|
|
1132
|
+
*/
|
|
1133
|
+
function encodeNumberOrString(value) {
|
|
1134
|
+
return typeof value === 'number'
|
|
1135
|
+
? { numberValue: value }
|
|
1136
|
+
: { stringValue: value };
|
|
1072
1137
|
}
|
|
1073
1138
|
/**
|
|
1074
1139
|
* Just a map with friendlier names for the types.
|
package/build/src/common.d.ts
CHANGED
|
@@ -59,6 +59,20 @@ export declare const AFE_SERVER_TIMING_HEADER = "x-goog-spanner-enable-afe-serve
|
|
|
59
59
|
export declare function addLeaderAwareRoutingHeader(headers: {
|
|
60
60
|
[k: string]: string;
|
|
61
61
|
}): void;
|
|
62
|
+
/**
|
|
63
|
+
* Returns whether AFE (Application Frontend Extension) server timing is enabled.
|
|
64
|
+
*
|
|
65
|
+
* This function checks the value of the environment variable
|
|
66
|
+
* `SPANNER_DISABLE_AFE_SERVER_TIMING`. If the variable is set to the
|
|
67
|
+
* string `'true'` (case-insensitive), then AFE server timing is considered disabled,
|
|
68
|
+
* and this function returns `false`. For all other values (including if the variable is unset),
|
|
69
|
+
* the function returns `true`.
|
|
70
|
+
*
|
|
71
|
+
* @returns {boolean} `true` if AFE server timing is enabled; otherwise, `false`.
|
|
72
|
+
*/
|
|
73
|
+
export declare function isAFEServerTimingEnabled(): boolean;
|
|
74
|
+
/** Resets the cached value (use in tests if env changes). */
|
|
75
|
+
export declare function resetAFEServerTimingForTest(): void;
|
|
62
76
|
/**
|
|
63
77
|
* Returns common headers to add.
|
|
64
78
|
* @param headers Common header list.
|
package/build/src/common.js
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.AFE_SERVER_TIMING_HEADER = exports.END_TO_END_TRACING_HEADER = exports.LEADER_AWARE_ROUTING_HEADER = exports.CLOUD_RESOURCE_HEADER = void 0;
|
|
19
19
|
exports.addLeaderAwareRoutingHeader = addLeaderAwareRoutingHeader;
|
|
20
|
+
exports.isAFEServerTimingEnabled = isAFEServerTimingEnabled;
|
|
21
|
+
exports.resetAFEServerTimingForTest = resetAFEServerTimingForTest;
|
|
20
22
|
exports.getCommonHeaders = getCommonHeaders;
|
|
21
23
|
/*!
|
|
22
24
|
* HTTP header for the resource prefix to improve routing
|
|
@@ -42,6 +44,30 @@ exports.AFE_SERVER_TIMING_HEADER = 'x-goog-spanner-enable-afe-server-timing';
|
|
|
42
44
|
function addLeaderAwareRoutingHeader(headers) {
|
|
43
45
|
headers[exports.LEADER_AWARE_ROUTING_HEADER] = 'true';
|
|
44
46
|
}
|
|
47
|
+
let isAFEServerTimingEnabledCached;
|
|
48
|
+
/**
|
|
49
|
+
* Returns whether AFE (Application Frontend Extension) server timing is enabled.
|
|
50
|
+
*
|
|
51
|
+
* This function checks the value of the environment variable
|
|
52
|
+
* `SPANNER_DISABLE_AFE_SERVER_TIMING`. If the variable is set to the
|
|
53
|
+
* string `'true'` (case-insensitive), then AFE server timing is considered disabled,
|
|
54
|
+
* and this function returns `false`. For all other values (including if the variable is unset),
|
|
55
|
+
* the function returns `true`.
|
|
56
|
+
*
|
|
57
|
+
* @returns {boolean} `true` if AFE server timing is enabled; otherwise, `false`.
|
|
58
|
+
*/
|
|
59
|
+
function isAFEServerTimingEnabled() {
|
|
60
|
+
if (isAFEServerTimingEnabledCached === undefined) {
|
|
61
|
+
isAFEServerTimingEnabledCached =
|
|
62
|
+
process.env['SPANNER_DISABLE_AFE_SERVER_TIMING']?.toLowerCase() !==
|
|
63
|
+
'true';
|
|
64
|
+
}
|
|
65
|
+
return isAFEServerTimingEnabledCached;
|
|
66
|
+
}
|
|
67
|
+
/** Resets the cached value (use in tests if env changes). */
|
|
68
|
+
function resetAFEServerTimingForTest() {
|
|
69
|
+
isAFEServerTimingEnabledCached = undefined;
|
|
70
|
+
}
|
|
45
71
|
/**
|
|
46
72
|
* Returns common headers to add.
|
|
47
73
|
* @param headers Common header list.
|
|
@@ -52,7 +78,7 @@ function getCommonHeaders(resourceName, enableTracing) {
|
|
|
52
78
|
enableTracing) {
|
|
53
79
|
headers[exports.END_TO_END_TRACING_HEADER] = 'true';
|
|
54
80
|
}
|
|
55
|
-
if (
|
|
81
|
+
if (isAFEServerTimingEnabled()) {
|
|
56
82
|
headers[exports.AFE_SERVER_TIMING_HEADER] = 'true';
|
|
57
83
|
}
|
|
58
84
|
headers[exports.CLOUD_RESOURCE_HEADER] = resourceName;
|
package/build/src/database.d.ts
CHANGED
|
@@ -54,6 +54,11 @@ type DatabaseResponse = [Database, r.Response];
|
|
|
54
54
|
type DatabaseCallback = ResourceCallback<Database, r.Response>;
|
|
55
55
|
type GetSnapshotCallback = NormalCallback<Snapshot>;
|
|
56
56
|
type GetTransactionCallback = NormalCallback<Transaction>;
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated Session pool is deprecated and will be removed in a future release.
|
|
59
|
+
Multiplexed sessions are now used for all operations by default, eliminating
|
|
60
|
+
the need for session pooling.
|
|
61
|
+
*/
|
|
57
62
|
export interface SessionPoolConstructor {
|
|
58
63
|
new (database: Database, options?: SessionPoolOptions | null): SessionPoolInterface;
|
|
59
64
|
}
|
|
@@ -161,10 +166,15 @@ export interface WriteAtLeastOnceOptions extends CallOptions {
|
|
|
161
166
|
* @class
|
|
162
167
|
*
|
|
163
168
|
* @param {string} name Name of the database.
|
|
164
|
-
* @param {SessionPoolOptions|SessionPoolInterface}
|
|
165
|
-
* configuration options
|
|
166
|
-
*
|
|
169
|
+
* @param {SessionPoolOptions|SessionPoolInterface} [poolOptions] Session pool
|
|
170
|
+
* configuration options.
|
|
171
|
+
* **Deprecated**. Session pool options is deprecated and will be removed in a future release.
|
|
172
|
+
* Multiplexed sessions are now used for all operations by default, eliminating
|
|
173
|
+
* the need for session pooling.
|
|
174
|
+
* @param {google.spanner.v1.ExecuteSqlRequest.IQueryOptions} [queryOptions]
|
|
167
175
|
* The default query options to use for queries on the database.
|
|
176
|
+
* @param {string} [databaseRole] The database role to use for sessions on
|
|
177
|
+
* the database.
|
|
168
178
|
*
|
|
169
179
|
* @example
|
|
170
180
|
* ```
|
|
@@ -180,7 +190,6 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
180
190
|
pool_: SessionPoolInterface;
|
|
181
191
|
sessionFactory_: SessionFactoryInterface;
|
|
182
192
|
queryOptions_?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions;
|
|
183
|
-
isMuxEnabledForRW_?: boolean;
|
|
184
193
|
commonHeaders_: {
|
|
185
194
|
[k: string]: string;
|
|
186
195
|
};
|
|
@@ -193,7 +202,14 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
193
202
|
_observabilityOptions?: ObservabilityOptions;
|
|
194
203
|
private _traceConfig;
|
|
195
204
|
private _nthRequest;
|
|
196
|
-
|
|
205
|
+
private _clientIdValue;
|
|
206
|
+
get _clientId(): number;
|
|
207
|
+
set _clientId(value: number);
|
|
208
|
+
private _channelIdValue;
|
|
209
|
+
get _channelId(): number;
|
|
210
|
+
set _channelId(value: number);
|
|
211
|
+
private _updateRequestIdPrefix;
|
|
212
|
+
_requestIdPrefix: string;
|
|
197
213
|
constructor(instance: Instance, name: string, poolOptions?: SessionPoolConstructor | SessionPoolOptions, queryOptions?: spannerClient.spanner.v1.ExecuteSqlRequest.IQueryOptions, databaseRole?: string | null);
|
|
198
214
|
_nextNthRequest(): number;
|
|
199
215
|
/**
|
|
@@ -359,7 +375,7 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
359
375
|
* @param {?Error} err Request error, if any.
|
|
360
376
|
*/
|
|
361
377
|
/**
|
|
362
|
-
* Close the database connection
|
|
378
|
+
* Close the database connection.
|
|
363
379
|
*
|
|
364
380
|
* @param {CloseDatabaseCallback} [callback] Callback function.
|
|
365
381
|
* @returns {Promise}
|
|
@@ -377,18 +393,6 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
377
393
|
* // Error handling omitted.
|
|
378
394
|
* }
|
|
379
395
|
* });
|
|
380
|
-
*
|
|
381
|
-
* //-
|
|
382
|
-
* // In the event of a session leak, the error object will contain a
|
|
383
|
-
* // `messages` field.
|
|
384
|
-
* //-
|
|
385
|
-
* database.close(function(err) {
|
|
386
|
-
* if (err && err.messages) {
|
|
387
|
-
* err.messages.forEach(function(message) {
|
|
388
|
-
* console.error(message);
|
|
389
|
-
* });
|
|
390
|
-
* }
|
|
391
|
-
* });
|
|
392
396
|
* ```
|
|
393
397
|
*/
|
|
394
398
|
close(callback: SessionPoolCloseCallback): void;
|
|
@@ -565,17 +569,6 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
565
569
|
createTable(schema: Schema, gaxOptions?: CallOptions): Promise<CreateTableResponse>;
|
|
566
570
|
createTable(schema: Schema, callback: CreateTableCallback): void;
|
|
567
571
|
createTable(schema: Schema, gaxOptions: CallOptions, callback: CreateTableCallback): void;
|
|
568
|
-
/**
|
|
569
|
-
* Decorates transaction so that when end() is called it will return the session
|
|
570
|
-
* back into the pool.
|
|
571
|
-
*
|
|
572
|
-
* @private
|
|
573
|
-
*
|
|
574
|
-
* @param {Session} session The session to release.
|
|
575
|
-
* @param {Transaction} transaction The transaction to observe.
|
|
576
|
-
* @returns {Transaction}
|
|
577
|
-
*/
|
|
578
|
-
private _releaseOnEnd;
|
|
579
572
|
/**
|
|
580
573
|
* @typedef {array} DatabaseDeleteResponse
|
|
581
574
|
* @property {object} 0 The full API response.
|
|
@@ -1109,8 +1102,7 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
1109
1102
|
* Wrapper around {@link v1.SpannerClient#beginTransaction}.
|
|
1110
1103
|
*
|
|
1111
1104
|
* **NOTE:** When finished with the Snapshot, {@link Snapshot#end} should be
|
|
1112
|
-
* called to
|
|
1113
|
-
* result in a Session leak.**
|
|
1105
|
+
* called to end the snapshot transaction.
|
|
1114
1106
|
*
|
|
1115
1107
|
* **NOTE:** Since the returned {@link Snapshot} transaction is not a
|
|
1116
1108
|
* single-use transaction, it is invalid to set the `minReadTimestamp` and
|
|
@@ -1170,9 +1162,8 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
1170
1162
|
*
|
|
1171
1163
|
* **NOTE:** In the event that you encounter an error while reading/writing,
|
|
1172
1164
|
* if you decide to forgo calling {@link Transaction#commit} or
|
|
1173
|
-
* {@link Transaction#rollback}, then you
|
|
1174
|
-
* {@link Transaction#end} to
|
|
1175
|
-
* **Failure to do could result in a Session leak.**
|
|
1165
|
+
* {@link Transaction#rollback}, then you should call
|
|
1166
|
+
* {@link Transaction#end} to end the transaction.
|
|
1176
1167
|
*
|
|
1177
1168
|
* Wrapper around {@link v1.SpannerClient#beginTransaction}.
|
|
1178
1169
|
*
|
|
@@ -1569,8 +1560,8 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
1569
1560
|
run(query: string | ExecuteSqlRequest, options: TimestampBounds, callback: RunCallback): void;
|
|
1570
1561
|
/**
|
|
1571
1562
|
* Always runs the query through the full streaming pipeline (Database.prototype.runStream).
|
|
1572
|
-
* Used when runStream has been overridden on Database
|
|
1573
|
-
*
|
|
1563
|
+
* Used when runStream has been overridden on Database to preserve backward compatibility
|
|
1564
|
+
* with custom stream implementations.
|
|
1574
1565
|
*
|
|
1575
1566
|
* @private
|
|
1576
1567
|
*/
|
|
@@ -1587,13 +1578,13 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
1587
1578
|
private _run;
|
|
1588
1579
|
/**
|
|
1589
1580
|
* Acquires a session and executes the query on a snapshot, managing span
|
|
1590
|
-
* lifetimes
|
|
1581
|
+
* lifetimes.
|
|
1591
1582
|
*
|
|
1592
1583
|
* @private
|
|
1593
1584
|
*/
|
|
1594
1585
|
private _executeRunOnSession;
|
|
1595
1586
|
/**
|
|
1596
|
-
* Executes the query on the snapshot
|
|
1587
|
+
* Executes the query on the snapshot.
|
|
1597
1588
|
*
|
|
1598
1589
|
* @private
|
|
1599
1590
|
*/
|
|
@@ -1772,9 +1763,8 @@ declare class Database extends common.GrpcServiceObject {
|
|
|
1772
1763
|
*
|
|
1773
1764
|
* **NOTE:** In the event that you encounter an error while reading/writing,
|
|
1774
1765
|
* if you decide to forgo calling {@link Transaction#commit} or
|
|
1775
|
-
* {@link Transaction#rollback}, then you
|
|
1776
|
-
* {@link Transaction#end} to
|
|
1777
|
-
* **Failure to do could result in a Session leak.**
|
|
1766
|
+
* {@link Transaction#rollback}, then you should call
|
|
1767
|
+
* {@link Transaction#end} to end the transaction.
|
|
1778
1768
|
*
|
|
1779
1769
|
* For a more complete listing of functionality available to a Transaction, see
|
|
1780
1770
|
* the {@link Transaction} API documentation. For a general overview of
|