@google-cloud/spanner 7.6.0 → 7.8.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 +29 -0
- package/README.md +4 -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 +15 -1
- package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +6 -0
- package/build/protos/google/spanner/executor/v1/cloud_executor.proto +30 -6
- 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 +310 -40
- package/build/protos/protos.js +942 -89
- package/build/protos/protos.json +115 -5
- package/build/src/codec.d.ts +56 -1
- package/build/src/codec.js +109 -4
- package/build/src/database.d.ts +41 -5
- package/build/src/database.js +37 -2
- package/build/src/index.d.ts +50 -1
- package/build/src/index.js +53 -0
- package/build/src/partial-result-stream.d.ts +41 -0
- package/build/src/partial-result-stream.js +6 -1
- 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 +3 -0
- package/build/src/transaction.d.ts +55 -0
- package/build/src/transaction.js +28 -2
- package/build/src/v1/database_admin_client.d.ts +175 -126
- package/build/src/v1/database_admin_client.js +95 -64
- package/build/src/v1/instance_admin_client.js +10 -7
- package/build/src/v1/spanner_client.js +10 -7
- package/build/src/v1/spanner_client_config.json +15 -14
- package/build/src/v1/spanner_executor_proxy_client.js +10 -7
- package/package.json +3 -3
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;
|
|
@@ -617,12 +627,27 @@ class Database extends common.GrpcServiceObject {
|
|
|
617
627
|
});
|
|
618
628
|
});
|
|
619
629
|
}
|
|
620
|
-
getTransaction(callback) {
|
|
630
|
+
getTransaction(optionsOrCallback, callback) {
|
|
631
|
+
const cb = typeof optionsOrCallback === 'function'
|
|
632
|
+
? optionsOrCallback
|
|
633
|
+
: callback;
|
|
634
|
+
const options = typeof optionsOrCallback === 'object' && optionsOrCallback
|
|
635
|
+
? optionsOrCallback
|
|
636
|
+
: {};
|
|
621
637
|
this.pool_.getSession((err, session, transaction) => {
|
|
638
|
+
if (options.requestOptions) {
|
|
639
|
+
transaction.requestOptions = Object.assign(transaction.requestOptions || {}, options.requestOptions);
|
|
640
|
+
}
|
|
641
|
+
if (options.optimisticLock) {
|
|
642
|
+
transaction.useOptimisticLock();
|
|
643
|
+
}
|
|
644
|
+
if (options.excludeTxnFromChangeStreams) {
|
|
645
|
+
transaction.excludeTxnFromChangeStreams();
|
|
646
|
+
}
|
|
622
647
|
if (!err) {
|
|
623
648
|
this._releaseOnEnd(session, transaction);
|
|
624
649
|
}
|
|
625
|
-
|
|
650
|
+
cb(err, transaction);
|
|
626
651
|
});
|
|
627
652
|
}
|
|
628
653
|
async getOperations(optionsOrCallback) {
|
|
@@ -799,6 +824,9 @@ class Database extends common.GrpcServiceObject {
|
|
|
799
824
|
}
|
|
800
825
|
_runPartitionedUpdate(session, query, callback) {
|
|
801
826
|
const transaction = session.partitionedDml();
|
|
827
|
+
if (typeof query !== 'string' && query.excludeTxnFromChangeStreams) {
|
|
828
|
+
transaction.excludeTxnFromChangeStreams();
|
|
829
|
+
}
|
|
802
830
|
transaction.begin(err => {
|
|
803
831
|
if (err) {
|
|
804
832
|
this.pool_.release(session);
|
|
@@ -1010,6 +1038,9 @@ class Database extends common.GrpcServiceObject {
|
|
|
1010
1038
|
if (options.optimisticLock) {
|
|
1011
1039
|
transaction.useOptimisticLock();
|
|
1012
1040
|
}
|
|
1041
|
+
if (options.excludeTxnFromChangeStreams) {
|
|
1042
|
+
transaction.excludeTxnFromChangeStreams();
|
|
1043
|
+
}
|
|
1013
1044
|
const release = this.pool_.release.bind(this.pool_, session);
|
|
1014
1045
|
const runner = new transaction_runner_1.TransactionRunner(session, transaction, runFn, options);
|
|
1015
1046
|
runner.run().then(release, err => {
|
|
@@ -1101,6 +1132,9 @@ class Database extends common.GrpcServiceObject {
|
|
|
1101
1132
|
if (options.optimisticLock) {
|
|
1102
1133
|
transaction.useOptimisticLock();
|
|
1103
1134
|
}
|
|
1135
|
+
if (options.excludeTxnFromChangeStreams) {
|
|
1136
|
+
transaction.excludeTxnFromChangeStreams();
|
|
1137
|
+
}
|
|
1104
1138
|
const runner = new transaction_runner_1.AsyncTransactionRunner(session, transaction, runFn, options);
|
|
1105
1139
|
try {
|
|
1106
1140
|
return await runner.run();
|
|
@@ -1227,6 +1261,7 @@ exports.Database = Database;
|
|
|
1227
1261
|
'batchTransaction',
|
|
1228
1262
|
'getRestoreInfo',
|
|
1229
1263
|
'getState',
|
|
1264
|
+
'getDatabaseDialect',
|
|
1230
1265
|
'getOperations',
|
|
1231
1266
|
'runTransaction',
|
|
1232
1267
|
'runTransactionAsync',
|
package/build/src/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { GrpcService } from './common-grpc/service';
|
|
|
18
18
|
import { PreciseDate } from '@google-cloud/precise-date';
|
|
19
19
|
import { GoogleAuth, GoogleAuthOptions } from 'google-auth-library';
|
|
20
20
|
import { common as p } from 'protobufjs';
|
|
21
|
-
import { Float32, Float, Int, Numeric, PGNumeric, PGJsonb, SpannerDate, Struct } from './codec';
|
|
21
|
+
import { Float32, Float, Int, Numeric, PGNumeric, PGJsonb, SpannerDate, Struct, ProtoMessage, ProtoEnum, IProtoMessageParams, IProtoEnumParams } from './codec';
|
|
22
22
|
import { Backup } from './backup';
|
|
23
23
|
import { Database } from './database';
|
|
24
24
|
import { Instance, CreateInstanceCallback, CreateInstanceResponse } from './instance';
|
|
@@ -968,6 +968,55 @@ declare class Spanner extends GrpcService {
|
|
|
968
968
|
* ```
|
|
969
969
|
*/
|
|
970
970
|
static pgJsonb(value: any): PGJsonb;
|
|
971
|
+
/**
|
|
972
|
+
* @typedef IProtoMessageParams
|
|
973
|
+
* @property {object} value Proto Message value as serialized-buffer or message object.
|
|
974
|
+
* @property {string} fullName Fully-qualified path name of proto message.
|
|
975
|
+
* @property {Function} [messageFunction] Function generated by protobufs containing
|
|
976
|
+
* helper methods for deserializing and serializing messages.
|
|
977
|
+
*/
|
|
978
|
+
/**
|
|
979
|
+
* Helper function to get a Cloud Spanner proto Message object.
|
|
980
|
+
*
|
|
981
|
+
* @param {IProtoMessageParams} params The proto message value params
|
|
982
|
+
* @returns {ProtoMessage}
|
|
983
|
+
*
|
|
984
|
+
* @example
|
|
985
|
+
* ```
|
|
986
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
987
|
+
* const protoMessage = Spanner.protoMessage({
|
|
988
|
+
* value: singerInfo,
|
|
989
|
+
* messageFunction: music.SingerInfo,
|
|
990
|
+
* fullName: "examples.spanner.music.SingerInfo"
|
|
991
|
+
* });
|
|
992
|
+
* ```
|
|
993
|
+
*/
|
|
994
|
+
static protoMessage(params: IProtoMessageParams): ProtoMessage;
|
|
995
|
+
/**
|
|
996
|
+
* @typedef IProtoEnumParams
|
|
997
|
+
* @property {string | number} value Proto Enum value as a string constant or
|
|
998
|
+
* an integer constant.
|
|
999
|
+
* @property {string} fullName Fully-qualified path name of proto enum.
|
|
1000
|
+
* @property {object} [enumObject] An enum object generated by protobufjs-cli.
|
|
1001
|
+
*/
|
|
1002
|
+
/**
|
|
1003
|
+
* Helper function to get a Cloud Spanner proto enum object.
|
|
1004
|
+
*
|
|
1005
|
+
* @param {IProtoEnumParams} params The proto enum value params in the format of
|
|
1006
|
+
* @code{IProtoEnumParams}
|
|
1007
|
+
* @returns {ProtoEnum}
|
|
1008
|
+
*
|
|
1009
|
+
* @example
|
|
1010
|
+
* ```
|
|
1011
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
1012
|
+
* const protoEnum = Spanner.protoEnum({
|
|
1013
|
+
* value: 'ROCK',
|
|
1014
|
+
* enumObject: music.Genre,
|
|
1015
|
+
* fullName: "examples.spanner.music.Genre"
|
|
1016
|
+
* });
|
|
1017
|
+
* ```
|
|
1018
|
+
*/
|
|
1019
|
+
static protoEnum(params: IProtoEnumParams): ProtoEnum;
|
|
971
1020
|
/**
|
|
972
1021
|
* Helper function to get a Cloud Spanner Struct object.
|
|
973
1022
|
*
|
package/build/src/index.js
CHANGED
|
@@ -921,6 +921,59 @@ class Spanner extends service_1.GrpcService {
|
|
|
921
921
|
static pgJsonb(value) {
|
|
922
922
|
return new codec_1.codec.PGJsonb(value);
|
|
923
923
|
}
|
|
924
|
+
/**
|
|
925
|
+
* @typedef IProtoMessageParams
|
|
926
|
+
* @property {object} value Proto Message value as serialized-buffer or message object.
|
|
927
|
+
* @property {string} fullName Fully-qualified path name of proto message.
|
|
928
|
+
* @property {Function} [messageFunction] Function generated by protobufs containing
|
|
929
|
+
* helper methods for deserializing and serializing messages.
|
|
930
|
+
*/
|
|
931
|
+
/**
|
|
932
|
+
* Helper function to get a Cloud Spanner proto Message object.
|
|
933
|
+
*
|
|
934
|
+
* @param {IProtoMessageParams} params The proto message value params
|
|
935
|
+
* @returns {ProtoMessage}
|
|
936
|
+
*
|
|
937
|
+
* @example
|
|
938
|
+
* ```
|
|
939
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
940
|
+
* const protoMessage = Spanner.protoMessage({
|
|
941
|
+
* value: singerInfo,
|
|
942
|
+
* messageFunction: music.SingerInfo,
|
|
943
|
+
* fullName: "examples.spanner.music.SingerInfo"
|
|
944
|
+
* });
|
|
945
|
+
* ```
|
|
946
|
+
*/
|
|
947
|
+
static protoMessage(params) {
|
|
948
|
+
return new codec_1.codec.ProtoMessage(params);
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* @typedef IProtoEnumParams
|
|
952
|
+
* @property {string | number} value Proto Enum value as a string constant or
|
|
953
|
+
* an integer constant.
|
|
954
|
+
* @property {string} fullName Fully-qualified path name of proto enum.
|
|
955
|
+
* @property {object} [enumObject] An enum object generated by protobufjs-cli.
|
|
956
|
+
*/
|
|
957
|
+
/**
|
|
958
|
+
* Helper function to get a Cloud Spanner proto enum object.
|
|
959
|
+
*
|
|
960
|
+
* @param {IProtoEnumParams} params The proto enum value params in the format of
|
|
961
|
+
* @code{IProtoEnumParams}
|
|
962
|
+
* @returns {ProtoEnum}
|
|
963
|
+
*
|
|
964
|
+
* @example
|
|
965
|
+
* ```
|
|
966
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
967
|
+
* const protoEnum = Spanner.protoEnum({
|
|
968
|
+
* value: 'ROCK',
|
|
969
|
+
* enumObject: music.Genre,
|
|
970
|
+
* fullName: "examples.spanner.music.Genre"
|
|
971
|
+
* });
|
|
972
|
+
* ```
|
|
973
|
+
*/
|
|
974
|
+
static protoEnum(params) {
|
|
975
|
+
return new codec_1.codec.ProtoEnum(params);
|
|
976
|
+
}
|
|
924
977
|
/**
|
|
925
978
|
* Helper function to get a Cloud Spanner Struct object.
|
|
926
979
|
*
|
|
@@ -36,11 +36,52 @@ interface RequestFunction {
|
|
|
36
36
|
* that it is not ready for any more data. Increase this value if you
|
|
37
37
|
* experience 'Stream is still not ready to receive data' errors as a
|
|
38
38
|
* result of a slow writer in your receiving stream.
|
|
39
|
+
* @property {object} [columnsMetadata] An object map that can be used to pass
|
|
40
|
+
* additional properties for each column type which can help in deserializing
|
|
41
|
+
* the data coming from backend. (Eg: We need to pass Proto Function and Enum
|
|
42
|
+
* map to deserialize proto messages and enums, respectively.)
|
|
39
43
|
*/
|
|
40
44
|
export interface RowOptions {
|
|
41
45
|
json?: boolean;
|
|
42
46
|
jsonOptions?: JSONOptions;
|
|
43
47
|
maxResumeRetries?: number;
|
|
48
|
+
/**
|
|
49
|
+
* An object where column names as keys and custom objects as corresponding
|
|
50
|
+
* values for deserialization. It's specifically useful for data types like
|
|
51
|
+
* protobuf where deserialization logic is on user-specific code. When provided,
|
|
52
|
+
* the custom object enables deserialization of backend-received column data.
|
|
53
|
+
* If not provided, data remains serialized as buffer for Proto Messages and
|
|
54
|
+
* integer for Proto Enums.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* To obtain Proto Messages and Proto Enums as JSON objects, you must supply
|
|
58
|
+
* additional metadata. This metadata should include the protobufjs-cli
|
|
59
|
+
* generated proto message function and enum object. It encompasses the essential
|
|
60
|
+
* logic for proper data deserialization.
|
|
61
|
+
*
|
|
62
|
+
* Eg: To read data from Proto Columns in json format using DQL, you should pass
|
|
63
|
+
* columnsMetadata where key is the name of the column and value is the protobufjs-cli
|
|
64
|
+
* generated proto message function and enum object.
|
|
65
|
+
*
|
|
66
|
+
* const query = {
|
|
67
|
+
* sql: `SELECT SingerId,
|
|
68
|
+
* FirstName,
|
|
69
|
+
* LastName,
|
|
70
|
+
* SingerInfo,
|
|
71
|
+
* SingerGenre,
|
|
72
|
+
* SingerInfoArray,
|
|
73
|
+
* SingerGenreArray
|
|
74
|
+
* FROM Singers
|
|
75
|
+
* WHERE SingerId = 6`,
|
|
76
|
+
* columnsMetadata: {
|
|
77
|
+
* SingerInfo: music.SingerInfo,
|
|
78
|
+
* SingerInfoArray: music.SingerInfo,
|
|
79
|
+
* SingerGenre: music.Genre,
|
|
80
|
+
* SingerGenreArray: music.Genre,
|
|
81
|
+
* },
|
|
82
|
+
* };
|
|
83
|
+
*/
|
|
84
|
+
columnsMetadata?: object;
|
|
44
85
|
}
|
|
45
86
|
/**
|
|
46
87
|
* By default rows are an Array of values in the form of objects containing
|
|
@@ -198,8 +198,13 @@ class PartialResultStream extends stream_1.Transform {
|
|
|
198
198
|
*/
|
|
199
199
|
_createRow(values) {
|
|
200
200
|
const fields = values.map((value, index) => {
|
|
201
|
+
var _a;
|
|
201
202
|
const { name, type } = this._fields[index];
|
|
202
|
-
|
|
203
|
+
const columnMetadata = (_a = this._options.columnsMetadata) === null || _a === void 0 ? void 0 : _a[name];
|
|
204
|
+
return {
|
|
205
|
+
name,
|
|
206
|
+
value: codec_1.codec.decode(value, type, columnMetadata),
|
|
207
|
+
};
|
|
203
208
|
});
|
|
204
209
|
Object.defineProperty(fields, 'toJSON', {
|
|
205
210
|
value: (options) => {
|
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.
|
|
@@ -121,6 +121,9 @@ class Runner {
|
|
|
121
121
|
if (this.options.optimisticLock) {
|
|
122
122
|
transaction.useOptimisticLock();
|
|
123
123
|
}
|
|
124
|
+
if (this.options.excludeTxnFromChangeStreams) {
|
|
125
|
+
transaction.excludeTxnFromChangeStreams();
|
|
126
|
+
}
|
|
124
127
|
if (this.attempts > 0) {
|
|
125
128
|
await transaction.begin();
|
|
126
129
|
}
|
|
@@ -45,6 +45,43 @@ export interface RequestOptions {
|
|
|
45
45
|
jsonOptions?: JSONOptions;
|
|
46
46
|
gaxOptions?: CallOptions;
|
|
47
47
|
maxResumeRetries?: number;
|
|
48
|
+
/**
|
|
49
|
+
* An object where column names as keys and custom objects as corresponding
|
|
50
|
+
* values for deserialization. This is only needed for proto columns
|
|
51
|
+
* where deserialization logic is on user-specific code. When provided,
|
|
52
|
+
* the custom object enables deserialization of backend-received column data.
|
|
53
|
+
* If not provided, data remains serialized as buffer for Proto Messages and
|
|
54
|
+
* integer for Proto Enums.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* To obtain Proto Messages and Proto Enums as JSON objects, you must supply
|
|
58
|
+
* additional metadata. This metadata should include the protobufjs-cli
|
|
59
|
+
* generated proto message function and enum object. It encompasses the essential
|
|
60
|
+
* logic for proper data deserialization.
|
|
61
|
+
*
|
|
62
|
+
* Eg: To read data from Proto Columns in json format using DQL, you should pass
|
|
63
|
+
* columnsMetadata where key is the name of the column and value is the protobufjs-cli
|
|
64
|
+
* generated proto message function and enum object.
|
|
65
|
+
*
|
|
66
|
+
* const query = {
|
|
67
|
+
* sql: `SELECT SingerId,
|
|
68
|
+
* FirstName,
|
|
69
|
+
* LastName,
|
|
70
|
+
* SingerInfo,
|
|
71
|
+
* SingerGenre,
|
|
72
|
+
* SingerInfoArray,
|
|
73
|
+
* SingerGenreArray
|
|
74
|
+
* FROM Singers
|
|
75
|
+
* WHERE SingerId = 6`,
|
|
76
|
+
* columnsMetadata: {
|
|
77
|
+
* SingerInfo: music.SingerInfo,
|
|
78
|
+
* SingerInfoArray: music.SingerInfo,
|
|
79
|
+
* SingerGenre: music.Genre,
|
|
80
|
+
* SingerGenreArray: music.Genre,
|
|
81
|
+
* },
|
|
82
|
+
* };
|
|
83
|
+
*/
|
|
84
|
+
columnsMetadata?: object;
|
|
48
85
|
}
|
|
49
86
|
export interface CommitOptions {
|
|
50
87
|
requestOptions?: Pick<IRequestOptions, 'priority'>;
|
|
@@ -1452,6 +1489,15 @@ export declare class Transaction extends Dml {
|
|
|
1452
1489
|
* mutations to the read data at a commit timestamp after the read timestamp).
|
|
1453
1490
|
*/
|
|
1454
1491
|
useOptimisticLock(): void;
|
|
1492
|
+
/**
|
|
1493
|
+
* Use option excludeTxnFromChangeStreams to exclude read/write transactions
|
|
1494
|
+
* from being tracked in change streams.
|
|
1495
|
+
*
|
|
1496
|
+
* Enabling this options to true will effectively disable change stream tracking
|
|
1497
|
+
* for a specified transaction, allowing read/write transaction to operate without being
|
|
1498
|
+
* included in change streams.
|
|
1499
|
+
*/
|
|
1500
|
+
excludeTxnFromChangeStreams(): void;
|
|
1455
1501
|
}
|
|
1456
1502
|
/**
|
|
1457
1503
|
* This type of transaction is used to execute a single Partitioned DML
|
|
@@ -1469,6 +1515,15 @@ export declare class Transaction extends Dml {
|
|
|
1469
1515
|
*/
|
|
1470
1516
|
export declare class PartitionedDml extends Dml {
|
|
1471
1517
|
constructor(session: Session, options?: spannerClient.spanner.v1.TransactionOptions.PartitionedDml);
|
|
1518
|
+
/**
|
|
1519
|
+
* Use option excludeTxnFromChangeStreams to exclude partitionedDml
|
|
1520
|
+
* queries from being tracked in change streams.
|
|
1521
|
+
*
|
|
1522
|
+
* Enabling this options to true will effectively disable change stream tracking
|
|
1523
|
+
* for a specified partitionedDml query, allowing write queries to operate
|
|
1524
|
+
* without being included in change streams.
|
|
1525
|
+
*/
|
|
1526
|
+
excludeTxnFromChangeStreams(): void;
|
|
1472
1527
|
/**
|
|
1473
1528
|
* Execute a DML statement and get the affected row count. Unlike
|
|
1474
1529
|
* {@link Transaction#runUpdate} after using this method you should
|
package/build/src/transaction.js
CHANGED
|
@@ -354,7 +354,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
354
354
|
*/
|
|
355
355
|
createReadStream(table, request = {}) {
|
|
356
356
|
var _a, _b, _c;
|
|
357
|
-
const { gaxOptions, json, jsonOptions, maxResumeRetries, requestOptions } = request;
|
|
357
|
+
const { gaxOptions, json, jsonOptions, maxResumeRetries, requestOptions, columnsMetadata, } = request;
|
|
358
358
|
const keySet = Snapshot.encodeKeySet(request);
|
|
359
359
|
const transaction = {};
|
|
360
360
|
if (this.id) {
|
|
@@ -376,6 +376,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
376
376
|
delete request.ranges;
|
|
377
377
|
delete request.requestOptions;
|
|
378
378
|
delete request.directedReadOptions;
|
|
379
|
+
delete request.columnsMetadata;
|
|
379
380
|
const reqOpts = Object.assign(request, {
|
|
380
381
|
session: this.session.formattedName_,
|
|
381
382
|
requestOptions: this.configureTagOptions(typeof transaction.singleUse !== 'undefined', (_b = (_a = this.requestOptions) === null || _a === void 0 ? void 0 : _a.transactionTag) !== null && _b !== void 0 ? _b : undefined, requestOptions),
|
|
@@ -407,6 +408,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
407
408
|
json,
|
|
408
409
|
jsonOptions,
|
|
409
410
|
maxResumeRetries,
|
|
411
|
+
columnsMetadata,
|
|
410
412
|
})) === null || _c === void 0 ? void 0 : _c.on('response', response => {
|
|
411
413
|
if (response.metadata && response.metadata.transaction && !this.id) {
|
|
412
414
|
this._update(response.metadata.transaction);
|
|
@@ -609,7 +611,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
609
611
|
}
|
|
610
612
|
query = Object.assign({}, query);
|
|
611
613
|
query.queryOptions = Object.assign(Object.assign({}, this.queryOptions), query.queryOptions);
|
|
612
|
-
const { gaxOptions, json, jsonOptions, maxResumeRetries, requestOptions } = query;
|
|
614
|
+
const { gaxOptions, json, jsonOptions, maxResumeRetries, requestOptions, columnsMetadata, } = query;
|
|
613
615
|
let reqOpts;
|
|
614
616
|
const directedReadOptions = this._getDirectedReadOptions(query.directedReadOptions);
|
|
615
617
|
const sanitizeRequest = () => {
|
|
@@ -633,6 +635,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
633
635
|
delete query.requestOptions;
|
|
634
636
|
delete query.types;
|
|
635
637
|
delete query.directedReadOptions;
|
|
638
|
+
delete query.columnsMetadata;
|
|
636
639
|
reqOpts = Object.assign(query, {
|
|
637
640
|
session: this.session.formattedName_,
|
|
638
641
|
seqno: this._seqno++,
|
|
@@ -672,6 +675,7 @@ class Snapshot extends events_1.EventEmitter {
|
|
|
672
675
|
json,
|
|
673
676
|
jsonOptions,
|
|
674
677
|
maxResumeRetries,
|
|
678
|
+
columnsMetadata,
|
|
675
679
|
})
|
|
676
680
|
.on('response', response => {
|
|
677
681
|
if (response.metadata && response.metadata.transaction && !this.id) {
|
|
@@ -1523,6 +1527,17 @@ class Transaction extends Dml {
|
|
|
1523
1527
|
useOptimisticLock() {
|
|
1524
1528
|
this._options.readWrite.readLockMode = ReadLockMode.OPTIMISTIC;
|
|
1525
1529
|
}
|
|
1530
|
+
/**
|
|
1531
|
+
* Use option excludeTxnFromChangeStreams to exclude read/write transactions
|
|
1532
|
+
* from being tracked in change streams.
|
|
1533
|
+
*
|
|
1534
|
+
* Enabling this options to true will effectively disable change stream tracking
|
|
1535
|
+
* for a specified transaction, allowing read/write transaction to operate without being
|
|
1536
|
+
* included in change streams.
|
|
1537
|
+
*/
|
|
1538
|
+
excludeTxnFromChangeStreams() {
|
|
1539
|
+
this._options.excludeTxnFromChangeStreams = true;
|
|
1540
|
+
}
|
|
1526
1541
|
}
|
|
1527
1542
|
exports.Transaction = Transaction;
|
|
1528
1543
|
/*! Developer Documentation
|
|
@@ -1552,6 +1567,17 @@ class PartitionedDml extends Dml {
|
|
|
1552
1567
|
super(session);
|
|
1553
1568
|
this._options = { partitionedDml: options };
|
|
1554
1569
|
}
|
|
1570
|
+
/**
|
|
1571
|
+
* Use option excludeTxnFromChangeStreams to exclude partitionedDml
|
|
1572
|
+
* queries from being tracked in change streams.
|
|
1573
|
+
*
|
|
1574
|
+
* Enabling this options to true will effectively disable change stream tracking
|
|
1575
|
+
* for a specified partitionedDml query, allowing write queries to operate
|
|
1576
|
+
* without being included in change streams.
|
|
1577
|
+
*/
|
|
1578
|
+
excludeTxnFromChangeStreams() {
|
|
1579
|
+
this._options.excludeTxnFromChangeStreams = true;
|
|
1580
|
+
}
|
|
1555
1581
|
runUpdate(query, callback) {
|
|
1556
1582
|
super.runUpdate(query, (err, count) => {
|
|
1557
1583
|
this.end();
|