@google-cloud/spanner 7.7.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 +16 -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 +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 +56 -1
- package/build/src/codec.js +109 -4
- package/build/src/database.d.ts +34 -4
- package/build/src/database.js +23 -0
- 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 +85 -57
- package/build/src/v1/spanner_client_config.json +15 -14
- package/package.json +3 -3
|
@@ -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();
|