@google-cloud/spanner 7.7.0 → 7.9.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/CHANGELOG.md +31 -0
- package/README.md +5 -0
- package/build/protos/google/spanner/admin/database/v1/backup.proto +190 -109
- package/build/protos/google/spanner/admin/database/v1/common.proto +30 -10
- package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +166 -100
- package/build/protos/google/spanner/admin/instance/v1/common.proto +1 -1
- package/build/protos/google/spanner/executor/v1/cloud_executor.proto +1 -1
- package/build/protos/google/spanner/v1/commit_response.proto +1 -1
- package/build/protos/google/spanner/v1/keys.proto +1 -1
- package/build/protos/google/spanner/v1/mutation.proto +1 -1
- package/build/protos/google/spanner/v1/query_plan.proto +1 -1
- package/build/protos/google/spanner/v1/result_set.proto +1 -1
- package/build/protos/google/spanner/v1/spanner.proto +1 -1
- package/build/protos/google/spanner/v1/transaction.proto +1 -1
- package/build/protos/google/spanner/v1/type.proto +1 -1
- package/build/protos/protos.d.ts +30 -0
- package/build/protos/protos.js +204 -0
- package/build/protos/protos.json +43 -0
- package/build/src/codec.d.ts +55 -1
- package/build/src/codec.js +109 -4
- package/build/src/common-grpc/service.d.ts +0 -1
- package/build/src/common.js +2 -2
- package/build/src/database.d.ts +94 -7
- package/build/src/database.js +131 -0
- package/build/src/index.d.ts +59 -3
- package/build/src/index.js +55 -1
- package/build/src/instance.d.ts +0 -2
- package/build/src/partial-result-stream.d.ts +41 -1
- package/build/src/partial-result-stream.js +8 -3
- package/build/src/session-pool.d.ts +0 -2
- package/build/src/session-pool.js +7 -7
- package/build/src/table.d.ts +1 -0
- package/build/src/table.js +36 -2
- package/build/src/transaction-runner.d.ts +1 -0
- package/build/src/transaction-runner.js +5 -2
- package/build/src/transaction.d.ts +100 -2
- package/build/src/transaction.js +135 -30
- package/build/src/v1/database_admin_client.d.ts +175 -127
- package/build/src/v1/database_admin_client.js +85 -57
- package/build/src/v1/instance_admin_client.d.ts +0 -1
- package/build/src/v1/spanner_client.d.ts +0 -1
- package/build/src/v1/spanner_client_config.json +15 -14
- package/package.json +6 -6
package/build/src/database.js
CHANGED
|
@@ -442,6 +442,16 @@ class Database extends common.GrpcServiceObject {
|
|
|
442
442
|
const [metadata] = await this.getMetadata(gaxOptions);
|
|
443
443
|
return metadata.state || undefined;
|
|
444
444
|
}
|
|
445
|
+
async getDatabaseDialect(optionsOrCallback, cb) {
|
|
446
|
+
const gaxOptions = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
447
|
+
if (this.databaseDialect === 'DATABASE_DIALECT_UNSPECIFIED' ||
|
|
448
|
+
this.databaseDialect === null ||
|
|
449
|
+
this.databaseDialect === undefined) {
|
|
450
|
+
const [metadata] = await this.getMetadata(gaxOptions);
|
|
451
|
+
this.databaseDialect = metadata.databaseDialect;
|
|
452
|
+
}
|
|
453
|
+
return this.databaseDialect || undefined;
|
|
454
|
+
}
|
|
445
455
|
getSchema(optionsOrCallback, cb) {
|
|
446
456
|
const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
447
457
|
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
@@ -631,6 +641,9 @@ class Database extends common.GrpcServiceObject {
|
|
|
631
641
|
if (options.optimisticLock) {
|
|
632
642
|
transaction.useOptimisticLock();
|
|
633
643
|
}
|
|
644
|
+
if (options.excludeTxnFromChangeStreams) {
|
|
645
|
+
transaction.excludeTxnFromChangeStreams();
|
|
646
|
+
}
|
|
634
647
|
if (!err) {
|
|
635
648
|
this._releaseOnEnd(session, transaction);
|
|
636
649
|
}
|
|
@@ -811,6 +824,9 @@ class Database extends common.GrpcServiceObject {
|
|
|
811
824
|
}
|
|
812
825
|
_runPartitionedUpdate(session, query, callback) {
|
|
813
826
|
const transaction = session.partitionedDml();
|
|
827
|
+
if (typeof query !== 'string' && query.excludeTxnFromChangeStreams) {
|
|
828
|
+
transaction.excludeTxnFromChangeStreams();
|
|
829
|
+
}
|
|
814
830
|
transaction.begin(err => {
|
|
815
831
|
if (err) {
|
|
816
832
|
this.pool_.release(session);
|
|
@@ -1022,6 +1038,9 @@ class Database extends common.GrpcServiceObject {
|
|
|
1022
1038
|
if (options.optimisticLock) {
|
|
1023
1039
|
transaction.useOptimisticLock();
|
|
1024
1040
|
}
|
|
1041
|
+
if (options.excludeTxnFromChangeStreams) {
|
|
1042
|
+
transaction.excludeTxnFromChangeStreams();
|
|
1043
|
+
}
|
|
1025
1044
|
const release = this.pool_.release.bind(this.pool_, session);
|
|
1026
1045
|
const runner = new transaction_runner_1.TransactionRunner(session, transaction, runFn, options);
|
|
1027
1046
|
runner.run().then(release, err => {
|
|
@@ -1113,6 +1132,9 @@ class Database extends common.GrpcServiceObject {
|
|
|
1113
1132
|
if (options.optimisticLock) {
|
|
1114
1133
|
transaction.useOptimisticLock();
|
|
1115
1134
|
}
|
|
1135
|
+
if (options.excludeTxnFromChangeStreams) {
|
|
1136
|
+
transaction.excludeTxnFromChangeStreams();
|
|
1137
|
+
}
|
|
1116
1138
|
const runner = new transaction_runner_1.AsyncTransactionRunner(session, transaction, runFn, options);
|
|
1117
1139
|
try {
|
|
1118
1140
|
return await runner.run();
|
|
@@ -1128,6 +1150,112 @@ class Database extends common.GrpcServiceObject {
|
|
|
1128
1150
|
}
|
|
1129
1151
|
}
|
|
1130
1152
|
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Write a batch of mutations to Spanner.
|
|
1155
|
+
*
|
|
1156
|
+
* All mutations in a group are committed atomically. However, mutations across
|
|
1157
|
+
* groups can be committed non-atomically in an unspecified order and thus, they
|
|
1158
|
+
* must be independent of each other. Partial failure is possible, i.e., some groups
|
|
1159
|
+
* may have been committed successfully, while some may have failed. The results of
|
|
1160
|
+
* individual batches are streamed into the response as the batches are applied.
|
|
1161
|
+
*
|
|
1162
|
+
* batchWriteAtLeastOnce requests are not replay protected, meaning that each mutation group may
|
|
1163
|
+
* be applied more than once. Replays of non-idempotent mutations may have undesirable
|
|
1164
|
+
* effects. For example, replays of an insert mutation may produce an already exists
|
|
1165
|
+
* error or if you use generated or commit timestamp-based keys, it may result in additional
|
|
1166
|
+
* rows being added to the mutation's table. We recommend structuring your mutation groups to
|
|
1167
|
+
* be idempotent to avoid this issue.
|
|
1168
|
+
*
|
|
1169
|
+
* @method Spanner#batchWriteAtLeastOnce
|
|
1170
|
+
*
|
|
1171
|
+
* @param {MutationGroup[]} [mutationGroups] The group of mutations to be applied.
|
|
1172
|
+
* @param {BatchWriteOptions} [options] Options object for batch write request.
|
|
1173
|
+
*
|
|
1174
|
+
* @returns {ReadableStream} An object stream which emits
|
|
1175
|
+
* {@link protos.google.spanner.v1.BatchWriteResponse|BatchWriteResponse}
|
|
1176
|
+
* on 'data' event.
|
|
1177
|
+
*
|
|
1178
|
+
* @example
|
|
1179
|
+
* ```
|
|
1180
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
1181
|
+
* const spanner = new Spanner();
|
|
1182
|
+
*
|
|
1183
|
+
* const instance = spanner.instance('my-instance');
|
|
1184
|
+
* const database = instance.database('my-database');
|
|
1185
|
+
* const mutationGroup = new MutationGroup();
|
|
1186
|
+
* mutationGroup.insert('Singers', {
|
|
1187
|
+
* SingerId: '1',
|
|
1188
|
+
* FirstName: 'Marc',
|
|
1189
|
+
* LastName: 'Richards',
|
|
1190
|
+
* });
|
|
1191
|
+
*
|
|
1192
|
+
* database.batchWriteAtLeastOnce([mutationGroup])
|
|
1193
|
+
* .on('error', console.error)
|
|
1194
|
+
* .on('data', response => {
|
|
1195
|
+
* console.log('response: ', response);
|
|
1196
|
+
* })
|
|
1197
|
+
* .on('end', () => {
|
|
1198
|
+
* console.log('Request completed successfully');
|
|
1199
|
+
* });
|
|
1200
|
+
*
|
|
1201
|
+
* //-
|
|
1202
|
+
* // If you anticipate many results, you can end a stream early to prevent
|
|
1203
|
+
* // unnecessary processing and API requests.
|
|
1204
|
+
* //-
|
|
1205
|
+
* database.batchWriteAtLeastOnce()
|
|
1206
|
+
* .on('data', response => {
|
|
1207
|
+
* this.end();
|
|
1208
|
+
* });
|
|
1209
|
+
* ```
|
|
1210
|
+
*/
|
|
1211
|
+
batchWriteAtLeastOnce(mutationGroups, options) {
|
|
1212
|
+
const proxyStream = through.obj();
|
|
1213
|
+
this.pool_.getSession((err, session) => {
|
|
1214
|
+
if (err) {
|
|
1215
|
+
proxyStream.destroy(err);
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
const gaxOpts = extend(true, {}, options === null || options === void 0 ? void 0 : options.gaxOptions);
|
|
1219
|
+
const reqOpts = Object.assign({}, {
|
|
1220
|
+
session: session.formattedName_,
|
|
1221
|
+
mutationGroups: mutationGroups.map(mg => mg.proto()),
|
|
1222
|
+
requestOptions: options === null || options === void 0 ? void 0 : options.requestOptions,
|
|
1223
|
+
});
|
|
1224
|
+
let dataReceived = false;
|
|
1225
|
+
let dataStream = this.requestStream({
|
|
1226
|
+
client: 'SpannerClient',
|
|
1227
|
+
method: 'batchWrite',
|
|
1228
|
+
reqOpts,
|
|
1229
|
+
gaxOpts,
|
|
1230
|
+
headers: this.resourceHeader_,
|
|
1231
|
+
});
|
|
1232
|
+
dataStream
|
|
1233
|
+
.once('data', () => (dataReceived = true))
|
|
1234
|
+
.once('error', err => {
|
|
1235
|
+
if (!dataReceived &&
|
|
1236
|
+
(0, session_pool_1.isSessionNotFoundError)(err)) {
|
|
1237
|
+
// If there's a 'Session not found' error and we have not yet received
|
|
1238
|
+
// any data, we can safely retry the writes on a new session.
|
|
1239
|
+
// Register the error on the session so the pool can discard it.
|
|
1240
|
+
if (session) {
|
|
1241
|
+
session.lastError = err;
|
|
1242
|
+
}
|
|
1243
|
+
// Remove the current data stream from the end user stream.
|
|
1244
|
+
dataStream.unpipe(proxyStream);
|
|
1245
|
+
dataStream.end();
|
|
1246
|
+
// Create a new stream and add it to the end user stream.
|
|
1247
|
+
dataStream = this.batchWriteAtLeastOnce(mutationGroups, options);
|
|
1248
|
+
dataStream.pipe(proxyStream);
|
|
1249
|
+
}
|
|
1250
|
+
else {
|
|
1251
|
+
proxyStream.destroy(err);
|
|
1252
|
+
}
|
|
1253
|
+
})
|
|
1254
|
+
.once('end', () => this.pool_.release(session))
|
|
1255
|
+
.pipe(proxyStream);
|
|
1256
|
+
});
|
|
1257
|
+
return proxyStream;
|
|
1258
|
+
}
|
|
1131
1259
|
/**
|
|
1132
1260
|
* Create a Session object.
|
|
1133
1261
|
*
|
|
@@ -1237,8 +1365,10 @@ exports.Database = Database;
|
|
|
1237
1365
|
(0, promisify_1.promisifyAll)(Database, {
|
|
1238
1366
|
exclude: [
|
|
1239
1367
|
'batchTransaction',
|
|
1368
|
+
'batchWriteAtLeastOnce',
|
|
1240
1369
|
'getRestoreInfo',
|
|
1241
1370
|
'getState',
|
|
1371
|
+
'getDatabaseDialect',
|
|
1242
1372
|
'getOperations',
|
|
1243
1373
|
'runTransaction',
|
|
1244
1374
|
'runTransactionAsync',
|
|
@@ -1256,6 +1386,7 @@ exports.Database = Database;
|
|
|
1256
1386
|
'create',
|
|
1257
1387
|
'batchCreateSessions',
|
|
1258
1388
|
'batchTransaction',
|
|
1389
|
+
'batchWriteAtLeastOnce',
|
|
1259
1390
|
'close',
|
|
1260
1391
|
'createBatchTransaction',
|
|
1261
1392
|
'createSession',
|
package/build/src/index.d.ts
CHANGED
|
@@ -13,12 +13,11 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="node" />
|
|
17
16
|
import { GrpcService } from './common-grpc/service';
|
|
18
17
|
import { PreciseDate } from '@google-cloud/precise-date';
|
|
19
18
|
import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';
|
|
20
19
|
import { common as p } from 'protobufjs';
|
|
21
|
-
import { Float32, Float, Int, Numeric, PGNumeric, PGJsonb, SpannerDate, Struct } from './codec';
|
|
20
|
+
import { Float32, Float, Int, Numeric, PGNumeric, PGJsonb, SpannerDate, Struct, ProtoMessage, ProtoEnum, IProtoMessageParams, IProtoEnumParams } from './codec';
|
|
22
21
|
import { Backup } from './backup';
|
|
23
22
|
import { Database } from './database';
|
|
24
23
|
import { Instance, CreateInstanceCallback, CreateInstanceResponse } from './instance';
|
|
@@ -29,7 +28,7 @@ import { PagedOptions, PagedResponse, PagedCallback, PagedOptionsWithFilter, Nor
|
|
|
29
28
|
import { Session } from './session';
|
|
30
29
|
import { SessionPool } from './session-pool';
|
|
31
30
|
import { Table } from './table';
|
|
32
|
-
import { PartitionedDml, Snapshot, Transaction } from './transaction';
|
|
31
|
+
import { MutationGroup, PartitionedDml, Snapshot, Transaction } from './transaction';
|
|
33
32
|
import * as v1 from './v1';
|
|
34
33
|
export type IOperation = instanceAdmin.longrunning.IOperation;
|
|
35
34
|
export type GetInstancesOptions = PagedOptionsWithFilter;
|
|
@@ -968,6 +967,55 @@ declare class Spanner extends GrpcService {
|
|
|
968
967
|
* ```
|
|
969
968
|
*/
|
|
970
969
|
static pgJsonb(value: any): PGJsonb;
|
|
970
|
+
/**
|
|
971
|
+
* @typedef IProtoMessageParams
|
|
972
|
+
* @property {object} value Proto Message value as serialized-buffer or message object.
|
|
973
|
+
* @property {string} fullName Fully-qualified path name of proto message.
|
|
974
|
+
* @property {Function} [messageFunction] Function generated by protobufs containing
|
|
975
|
+
* helper methods for deserializing and serializing messages.
|
|
976
|
+
*/
|
|
977
|
+
/**
|
|
978
|
+
* Helper function to get a Cloud Spanner proto Message object.
|
|
979
|
+
*
|
|
980
|
+
* @param {IProtoMessageParams} params The proto message value params
|
|
981
|
+
* @returns {ProtoMessage}
|
|
982
|
+
*
|
|
983
|
+
* @example
|
|
984
|
+
* ```
|
|
985
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
986
|
+
* const protoMessage = Spanner.protoMessage({
|
|
987
|
+
* value: singerInfo,
|
|
988
|
+
* messageFunction: music.SingerInfo,
|
|
989
|
+
* fullName: "examples.spanner.music.SingerInfo"
|
|
990
|
+
* });
|
|
991
|
+
* ```
|
|
992
|
+
*/
|
|
993
|
+
static protoMessage(params: IProtoMessageParams): ProtoMessage;
|
|
994
|
+
/**
|
|
995
|
+
* @typedef IProtoEnumParams
|
|
996
|
+
* @property {string | number} value Proto Enum value as a string constant or
|
|
997
|
+
* an integer constant.
|
|
998
|
+
* @property {string} fullName Fully-qualified path name of proto enum.
|
|
999
|
+
* @property {object} [enumObject] An enum object generated by protobufjs-cli.
|
|
1000
|
+
*/
|
|
1001
|
+
/**
|
|
1002
|
+
* Helper function to get a Cloud Spanner proto enum object.
|
|
1003
|
+
*
|
|
1004
|
+
* @param {IProtoEnumParams} params The proto enum value params in the format of
|
|
1005
|
+
* @code{IProtoEnumParams}
|
|
1006
|
+
* @returns {ProtoEnum}
|
|
1007
|
+
*
|
|
1008
|
+
* @example
|
|
1009
|
+
* ```
|
|
1010
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
1011
|
+
* const protoEnum = Spanner.protoEnum({
|
|
1012
|
+
* value: 'ROCK',
|
|
1013
|
+
* enumObject: music.Genre,
|
|
1014
|
+
* fullName: "examples.spanner.music.Genre"
|
|
1015
|
+
* });
|
|
1016
|
+
* ```
|
|
1017
|
+
*/
|
|
1018
|
+
static protoEnum(params: IProtoEnumParams): ProtoEnum;
|
|
971
1019
|
/**
|
|
972
1020
|
* Helper function to get a Cloud Spanner Struct object.
|
|
973
1021
|
*
|
|
@@ -1107,6 +1155,14 @@ export { Snapshot };
|
|
|
1107
1155
|
* @type {Constructor}
|
|
1108
1156
|
*/
|
|
1109
1157
|
export { Transaction };
|
|
1158
|
+
/**
|
|
1159
|
+
* {@link MutationGroup} class.
|
|
1160
|
+
*
|
|
1161
|
+
* @name Spanner.MutationGroup
|
|
1162
|
+
* @see MutationGroup
|
|
1163
|
+
* @type {Constructor}
|
|
1164
|
+
*/
|
|
1165
|
+
export { MutationGroup };
|
|
1110
1166
|
/**
|
|
1111
1167
|
* @type {object}
|
|
1112
1168
|
* @property {constructor} DatabaseAdminClient
|
package/build/src/index.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.SpannerDate = exports.PGNumeric = exports.Numeric = exports.Struct = exports.Int = exports.Float = exports.Float32 = exports.protos = exports.v1 = exports.Transaction = exports.Snapshot = exports.PartitionedDml = exports.Table = exports.SessionPool = exports.Session = exports.Backup = exports.Database = exports.InstanceConfig = exports.Instance = exports.Spanner = void 0;
|
|
18
|
+
exports.SpannerDate = exports.PGNumeric = exports.Numeric = exports.Struct = exports.Int = exports.Float = exports.Float32 = exports.protos = exports.v1 = exports.MutationGroup = exports.Transaction = exports.Snapshot = exports.PartitionedDml = exports.Table = exports.SessionPool = exports.Session = exports.Backup = exports.Database = exports.InstanceConfig = exports.Instance = exports.Spanner = void 0;
|
|
19
19
|
const service_1 = require("./common-grpc/service");
|
|
20
20
|
const precise_date_1 = require("@google-cloud/precise-date");
|
|
21
21
|
const projectify_1 = require("@google-cloud/projectify");
|
|
@@ -51,6 +51,7 @@ Object.defineProperty(exports, "SessionPool", { enumerable: true, get: function
|
|
|
51
51
|
const table_1 = require("./table");
|
|
52
52
|
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return table_1.Table; } });
|
|
53
53
|
const transaction_1 = require("./transaction");
|
|
54
|
+
Object.defineProperty(exports, "MutationGroup", { enumerable: true, get: function () { return transaction_1.MutationGroup; } });
|
|
54
55
|
Object.defineProperty(exports, "PartitionedDml", { enumerable: true, get: function () { return transaction_1.PartitionedDml; } });
|
|
55
56
|
Object.defineProperty(exports, "Snapshot", { enumerable: true, get: function () { return transaction_1.Snapshot; } });
|
|
56
57
|
Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return transaction_1.Transaction; } });
|
|
@@ -921,6 +922,59 @@ class Spanner extends service_1.GrpcService {
|
|
|
921
922
|
static pgJsonb(value) {
|
|
922
923
|
return new codec_1.codec.PGJsonb(value);
|
|
923
924
|
}
|
|
925
|
+
/**
|
|
926
|
+
* @typedef IProtoMessageParams
|
|
927
|
+
* @property {object} value Proto Message value as serialized-buffer or message object.
|
|
928
|
+
* @property {string} fullName Fully-qualified path name of proto message.
|
|
929
|
+
* @property {Function} [messageFunction] Function generated by protobufs containing
|
|
930
|
+
* helper methods for deserializing and serializing messages.
|
|
931
|
+
*/
|
|
932
|
+
/**
|
|
933
|
+
* Helper function to get a Cloud Spanner proto Message object.
|
|
934
|
+
*
|
|
935
|
+
* @param {IProtoMessageParams} params The proto message value params
|
|
936
|
+
* @returns {ProtoMessage}
|
|
937
|
+
*
|
|
938
|
+
* @example
|
|
939
|
+
* ```
|
|
940
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
941
|
+
* const protoMessage = Spanner.protoMessage({
|
|
942
|
+
* value: singerInfo,
|
|
943
|
+
* messageFunction: music.SingerInfo,
|
|
944
|
+
* fullName: "examples.spanner.music.SingerInfo"
|
|
945
|
+
* });
|
|
946
|
+
* ```
|
|
947
|
+
*/
|
|
948
|
+
static protoMessage(params) {
|
|
949
|
+
return new codec_1.codec.ProtoMessage(params);
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* @typedef IProtoEnumParams
|
|
953
|
+
* @property {string | number} value Proto Enum value as a string constant or
|
|
954
|
+
* an integer constant.
|
|
955
|
+
* @property {string} fullName Fully-qualified path name of proto enum.
|
|
956
|
+
* @property {object} [enumObject] An enum object generated by protobufjs-cli.
|
|
957
|
+
*/
|
|
958
|
+
/**
|
|
959
|
+
* Helper function to get a Cloud Spanner proto enum object.
|
|
960
|
+
*
|
|
961
|
+
* @param {IProtoEnumParams} params The proto enum value params in the format of
|
|
962
|
+
* @code{IProtoEnumParams}
|
|
963
|
+
* @returns {ProtoEnum}
|
|
964
|
+
*
|
|
965
|
+
* @example
|
|
966
|
+
* ```
|
|
967
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
968
|
+
* const protoEnum = Spanner.protoEnum({
|
|
969
|
+
* value: 'ROCK',
|
|
970
|
+
* enumObject: music.Genre,
|
|
971
|
+
* fullName: "examples.spanner.music.Genre"
|
|
972
|
+
* });
|
|
973
|
+
* ```
|
|
974
|
+
*/
|
|
975
|
+
static protoEnum(params) {
|
|
976
|
+
return new codec_1.codec.ProtoEnum(params);
|
|
977
|
+
}
|
|
924
978
|
/**
|
|
925
979
|
* Helper function to get a Cloud Spanner Struct object.
|
|
926
980
|
*
|
package/build/src/instance.d.ts
CHANGED
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="node" />
|
|
17
|
-
/// <reference types="node" />
|
|
18
16
|
import { GetConfig } from '@google-cloud/common';
|
|
19
17
|
declare const common: any;
|
|
20
18
|
import { Database, SessionPoolConstructor } from './database';
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="node" />
|
|
17
16
|
import { Readable, Transform } from 'stream';
|
|
18
17
|
import { JSONOptions, Json, Field, Value } from './codec';
|
|
19
18
|
import { google } from '../protos/protos';
|
|
@@ -36,11 +35,52 @@ interface RequestFunction {
|
|
|
36
35
|
* that it is not ready for any more data. Increase this value if you
|
|
37
36
|
* experience 'Stream is still not ready to receive data' errors as a
|
|
38
37
|
* result of a slow writer in your receiving stream.
|
|
38
|
+
* @property {object} [columnsMetadata] An object map that can be used to pass
|
|
39
|
+
* additional properties for each column type which can help in deserializing
|
|
40
|
+
* the data coming from backend. (Eg: We need to pass Proto Function and Enum
|
|
41
|
+
* map to deserialize proto messages and enums, respectively.)
|
|
39
42
|
*/
|
|
40
43
|
export interface RowOptions {
|
|
41
44
|
json?: boolean;
|
|
42
45
|
jsonOptions?: JSONOptions;
|
|
43
46
|
maxResumeRetries?: number;
|
|
47
|
+
/**
|
|
48
|
+
* An object where column names as keys and custom objects as corresponding
|
|
49
|
+
* values for deserialization. It's specifically useful for data types like
|
|
50
|
+
* protobuf where deserialization logic is on user-specific code. When provided,
|
|
51
|
+
* the custom object enables deserialization of backend-received column data.
|
|
52
|
+
* If not provided, data remains serialized as buffer for Proto Messages and
|
|
53
|
+
* integer for Proto Enums.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* To obtain Proto Messages and Proto Enums as JSON objects, you must supply
|
|
57
|
+
* additional metadata. This metadata should include the protobufjs-cli
|
|
58
|
+
* generated proto message function and enum object. It encompasses the essential
|
|
59
|
+
* logic for proper data deserialization.
|
|
60
|
+
*
|
|
61
|
+
* Eg: To read data from Proto Columns in json format using DQL, you should pass
|
|
62
|
+
* columnsMetadata where key is the name of the column and value is the protobufjs-cli
|
|
63
|
+
* generated proto message function and enum object.
|
|
64
|
+
*
|
|
65
|
+
* const query = {
|
|
66
|
+
* sql: `SELECT SingerId,
|
|
67
|
+
* FirstName,
|
|
68
|
+
* LastName,
|
|
69
|
+
* SingerInfo,
|
|
70
|
+
* SingerGenre,
|
|
71
|
+
* SingerInfoArray,
|
|
72
|
+
* SingerGenreArray
|
|
73
|
+
* FROM Singers
|
|
74
|
+
* WHERE SingerId = 6`,
|
|
75
|
+
* columnsMetadata: {
|
|
76
|
+
* SingerInfo: music.SingerInfo,
|
|
77
|
+
* SingerInfoArray: music.SingerInfo,
|
|
78
|
+
* SingerGenre: music.Genre,
|
|
79
|
+
* SingerGenreArray: music.Genre,
|
|
80
|
+
* },
|
|
81
|
+
* };
|
|
82
|
+
*/
|
|
83
|
+
columnsMetadata?: object;
|
|
44
84
|
}
|
|
45
85
|
/**
|
|
46
86
|
* By default rows are an Array of values in the form of objects containing
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
18
|
+
exports.PartialResultStream = void 0;
|
|
19
|
+
exports.partialResultStream = partialResultStream;
|
|
19
20
|
const service_1 = require("./common-grpc/service");
|
|
20
21
|
const checkpointStream = require("checkpoint-stream");
|
|
21
22
|
const eventsIntercept = require("events-intercept");
|
|
@@ -198,8 +199,13 @@ class PartialResultStream extends stream_1.Transform {
|
|
|
198
199
|
*/
|
|
199
200
|
_createRow(values) {
|
|
200
201
|
const fields = values.map((value, index) => {
|
|
202
|
+
var _a;
|
|
201
203
|
const { name, type } = this._fields[index];
|
|
202
|
-
|
|
204
|
+
const columnMetadata = (_a = this._options.columnsMetadata) === null || _a === void 0 ? void 0 : _a[name];
|
|
205
|
+
return {
|
|
206
|
+
name,
|
|
207
|
+
value: codec_1.codec.decode(value, type, columnMetadata),
|
|
208
|
+
};
|
|
203
209
|
});
|
|
204
210
|
Object.defineProperty(fields, 'toJSON', {
|
|
205
211
|
value: (options) => {
|
|
@@ -377,7 +383,6 @@ function partialResultStream(requestFn, options) {
|
|
|
377
383
|
.on('paused', () => requestsStream.pause())
|
|
378
384
|
.on('resumed', () => requestsStream.resume()));
|
|
379
385
|
}
|
|
380
|
-
exports.partialResultStream = partialResultStream;
|
|
381
386
|
function _hasResumeToken(chunk) {
|
|
382
387
|
return is.defined(chunk.resumeToken) && chunk.resumeToken.length > 0;
|
|
383
388
|
}
|
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
/// <reference types="node" />
|
|
17
|
-
/// <reference types="node" />
|
|
18
16
|
import { EventEmitter } from 'events';
|
|
19
17
|
import PQueue from 'p-queue';
|
|
20
18
|
import { Database } from './database';
|
|
@@ -15,7 +15,13 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.SessionPool = exports.
|
|
18
|
+
exports.SessionPool = exports.SessionPoolExhaustedError = exports.SessionLeakError = exports.ReleaseError = void 0;
|
|
19
|
+
exports.isSessionNotFoundError = isSessionNotFoundError;
|
|
20
|
+
exports.isDatabaseNotFoundError = isDatabaseNotFoundError;
|
|
21
|
+
exports.isInstanceNotFoundError = isInstanceNotFoundError;
|
|
22
|
+
exports.isCreateSessionPermissionError = isCreateSessionPermissionError;
|
|
23
|
+
exports.isDefaultCredentialsNotSetError = isDefaultCredentialsNotSetError;
|
|
24
|
+
exports.isProjectIdNotSetInEnvironmentError = isProjectIdNotSetInEnvironmentError;
|
|
19
25
|
const events_1 = require("events");
|
|
20
26
|
const is = require("is");
|
|
21
27
|
const p_queue_1 = require("p-queue");
|
|
@@ -82,7 +88,6 @@ function isSessionNotFoundError(error) {
|
|
|
82
88
|
error.code === google_gax_1.grpc.status.NOT_FOUND &&
|
|
83
89
|
error.message.includes('Session not found'));
|
|
84
90
|
}
|
|
85
|
-
exports.isSessionNotFoundError = isSessionNotFoundError;
|
|
86
91
|
/**
|
|
87
92
|
* Checks whether the given error is a 'Database not found' error.
|
|
88
93
|
* @param {Error} error The error to check.
|
|
@@ -93,7 +98,6 @@ function isDatabaseNotFoundError(error) {
|
|
|
93
98
|
error.code === google_gax_1.grpc.status.NOT_FOUND &&
|
|
94
99
|
error.message.includes('Database not found'));
|
|
95
100
|
}
|
|
96
|
-
exports.isDatabaseNotFoundError = isDatabaseNotFoundError;
|
|
97
101
|
/**
|
|
98
102
|
* Checks whether the given error is an 'Instance not found' error.
|
|
99
103
|
* @param {Error} error The error to check.
|
|
@@ -104,7 +108,6 @@ function isInstanceNotFoundError(error) {
|
|
|
104
108
|
error.code === google_gax_1.grpc.status.NOT_FOUND &&
|
|
105
109
|
error.message.includes('Instance not found'));
|
|
106
110
|
}
|
|
107
|
-
exports.isInstanceNotFoundError = isInstanceNotFoundError;
|
|
108
111
|
/**
|
|
109
112
|
* Checks whether the given error is a 'Create session permission' error.
|
|
110
113
|
* @param {Error} error The error to check.
|
|
@@ -115,7 +118,6 @@ function isCreateSessionPermissionError(error) {
|
|
|
115
118
|
error.code === google_gax_1.grpc.status.PERMISSION_DENIED &&
|
|
116
119
|
error.message.includes('spanner.sessions.create'));
|
|
117
120
|
}
|
|
118
|
-
exports.isCreateSessionPermissionError = isCreateSessionPermissionError;
|
|
119
121
|
/**
|
|
120
122
|
* Checks whether the given error is a 'Could not load the default credentials' error.
|
|
121
123
|
* @param {Error} error The error to check.
|
|
@@ -125,7 +127,6 @@ function isDefaultCredentialsNotSetError(error) {
|
|
|
125
127
|
return (error !== undefined &&
|
|
126
128
|
error.message.includes('Could not load the default credentials'));
|
|
127
129
|
}
|
|
128
|
-
exports.isDefaultCredentialsNotSetError = isDefaultCredentialsNotSetError;
|
|
129
130
|
/**
|
|
130
131
|
* Checks whether the given error is an 'Unable to detect a Project Id in the current environment' error.
|
|
131
132
|
* @param {Error} error The error to check.
|
|
@@ -135,7 +136,6 @@ function isProjectIdNotSetInEnvironmentError(error) {
|
|
|
135
136
|
return (error !== undefined &&
|
|
136
137
|
error.message.includes('Unable to detect a Project Id in the current environment'));
|
|
137
138
|
}
|
|
138
|
-
exports.isProjectIdNotSetInEnvironmentError = isProjectIdNotSetInEnvironmentError;
|
|
139
139
|
/**
|
|
140
140
|
* Class used to manage connections to Spanner.
|
|
141
141
|
*
|
package/build/src/table.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export type DropTableResponse = UpdateSchemaResponse;
|
|
|
31
31
|
export type DropTableCallback = UpdateSchemaCallback;
|
|
32
32
|
interface MutateRowsOptions extends CommitOptions {
|
|
33
33
|
requestOptions?: Omit<IRequestOptions, 'requestTag'>;
|
|
34
|
+
excludeTxnFromChangeStreams?: boolean;
|
|
34
35
|
}
|
|
35
36
|
export type DeleteRowsCallback = CommitCallback;
|
|
36
37
|
export type DeleteRowsResponse = CommitResponse;
|
package/build/src/table.js
CHANGED
|
@@ -18,6 +18,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.Table = void 0;
|
|
19
19
|
const promisify_1 = require("@google-cloud/promisify");
|
|
20
20
|
const through = require("through2");
|
|
21
|
+
const GOOGLE_STANDARD_SQL = 'GOOGLE_STANDARD_SQL';
|
|
22
|
+
const POSTGRESQL = 'POSTGRESQL';
|
|
21
23
|
/**
|
|
22
24
|
* Create a Table object to interact with a table in a Cloud Spanner
|
|
23
25
|
* database.
|
|
@@ -143,7 +145,33 @@ class Table {
|
|
|
143
145
|
delete(gaxOptionsOrCallback, cb) {
|
|
144
146
|
const gaxOptions = typeof gaxOptionsOrCallback === 'object' ? gaxOptionsOrCallback : {};
|
|
145
147
|
const callback = typeof gaxOptionsOrCallback === 'function' ? gaxOptionsOrCallback : cb;
|
|
146
|
-
|
|
148
|
+
const [schema, table] = this.name.includes('.')
|
|
149
|
+
? this.name.split('.')
|
|
150
|
+
: [null, this.name];
|
|
151
|
+
let dropStatement = 'DROP TABLE `' + table + '`';
|
|
152
|
+
const performDelete = async () => {
|
|
153
|
+
const result = await this.database.getDatabaseDialect(gaxOptions);
|
|
154
|
+
if (result && result.includes(POSTGRESQL)) {
|
|
155
|
+
dropStatement = schema
|
|
156
|
+
? `DROP TABLE "${schema}"."${table}"`
|
|
157
|
+
: `DROP TABLE "${table}"`;
|
|
158
|
+
}
|
|
159
|
+
else if (result && result.includes(GOOGLE_STANDARD_SQL)) {
|
|
160
|
+
dropStatement = schema
|
|
161
|
+
? 'DROP TABLE `' + schema + '`.`' + table + '`'
|
|
162
|
+
: dropStatement;
|
|
163
|
+
}
|
|
164
|
+
const updateSchemaResult = callback
|
|
165
|
+
? this.database.updateSchema(dropStatement, gaxOptions, callback)
|
|
166
|
+
: this.database.updateSchema(dropStatement, gaxOptions);
|
|
167
|
+
return updateSchemaResult;
|
|
168
|
+
};
|
|
169
|
+
if (!callback) {
|
|
170
|
+
return performDelete();
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
performDelete();
|
|
174
|
+
}
|
|
147
175
|
}
|
|
148
176
|
deleteRows(keys, optionsOrCallback, cb) {
|
|
149
177
|
const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
@@ -201,7 +229,13 @@ class Table {
|
|
|
201
229
|
*/
|
|
202
230
|
_mutate(method, rows, options = {}, callback) {
|
|
203
231
|
const requestOptions = 'requestOptions' in options ? options.requestOptions : {};
|
|
204
|
-
|
|
232
|
+
const excludeTxnFromChangeStreams = 'excludeTxnFromChangeStreams' in options
|
|
233
|
+
? options.excludeTxnFromChangeStreams
|
|
234
|
+
: false;
|
|
235
|
+
this.database.runTransaction({
|
|
236
|
+
requestOptions: requestOptions,
|
|
237
|
+
excludeTxnFromChangeStreams: excludeTxnFromChangeStreams,
|
|
238
|
+
}, (err, transaction) => {
|
|
205
239
|
if (err) {
|
|
206
240
|
callback(err);
|
|
207
241
|
return;
|
|
@@ -28,6 +28,7 @@ export interface RunTransactionOptions {
|
|
|
28
28
|
timeout?: number;
|
|
29
29
|
requestOptions?: Pick<IRequestOptions, 'transactionTag'>;
|
|
30
30
|
optimisticLock?: boolean;
|
|
31
|
+
excludeTxnFromChangeStreams?: boolean;
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* A function to execute in the context of a transaction.
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
18
|
+
exports.AsyncTransactionRunner = exports.TransactionRunner = exports.Runner = exports.DeadlineError = void 0;
|
|
19
|
+
exports.isRetryableInternalError = isRetryableInternalError;
|
|
19
20
|
const promisify_1 = require("@google-cloud/promisify");
|
|
20
21
|
const google_gax_1 = require("google-gax");
|
|
21
22
|
const protobufjs_1 = require("protobufjs");
|
|
@@ -121,6 +122,9 @@ class Runner {
|
|
|
121
122
|
if (this.options.optimisticLock) {
|
|
122
123
|
transaction.useOptimisticLock();
|
|
123
124
|
}
|
|
125
|
+
if (this.options.excludeTxnFromChangeStreams) {
|
|
126
|
+
transaction.excludeTxnFromChangeStreams();
|
|
127
|
+
}
|
|
124
128
|
if (this.attempts > 0) {
|
|
125
129
|
await transaction.begin();
|
|
126
130
|
}
|
|
@@ -275,5 +279,4 @@ function isRetryableInternalError(err) {
|
|
|
275
279
|
err.message.includes('HTTP/2 error code: INTERNAL_ERROR') ||
|
|
276
280
|
err.message.includes('Connection closed with unknown cause')));
|
|
277
281
|
}
|
|
278
|
-
exports.isRetryableInternalError = isRetryableInternalError;
|
|
279
282
|
//# sourceMappingURL=transaction-runner.js.map
|