@google-cloud/spanner 7.18.0 → 7.19.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 +30 -0
- package/README.md +1 -0
- package/build/protos/google/spanner/admin/database/v1/backup.proto +773 -0
- package/build/protos/google/spanner/admin/database/v1/backup_schedule.proto +230 -0
- package/build/protos/google/spanner/admin/database/v1/common.proto +132 -0
- package/build/protos/google/spanner/admin/database/v1/spanner_database_admin.proto +1279 -0
- package/build/protos/google/spanner/admin/instance/v1/common.proto +64 -0
- package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +2110 -0
- package/build/protos/google/spanner/executor/v1/cloud_executor.proto +1520 -0
- package/build/protos/google/spanner/v1/commit_response.proto +59 -0
- package/build/protos/google/spanner/v1/keys.proto +163 -0
- package/build/protos/google/spanner/v1/mutation.proto +107 -0
- package/build/protos/google/spanner/v1/query_plan.proto +128 -0
- package/build/protos/google/spanner/v1/result_set.proto +237 -0
- package/build/protos/google/spanner/v1/spanner.proto +1389 -0
- package/build/protos/google/spanner/v1/transaction.proto +622 -0
- package/build/protos/google/spanner/v1/type.proto +214 -0
- package/build/protos/protos.d.ts +39869 -0
- package/build/protos/protos.js +101659 -0
- package/build/protos/protos.json +10391 -0
- package/build/src/backup.d.ts +349 -0
- package/build/src/backup.js +246 -0
- package/build/src/batch-transaction.d.ts +247 -0
- package/build/src/batch-transaction.js +384 -0
- package/build/src/codec.d.ts +362 -0
- package/build/src/codec.js +791 -0
- package/build/src/common-grpc/service-object.d.ts +80 -0
- package/build/src/common-grpc/service-object.js +101 -0
- package/build/src/common-grpc/service.d.ts +445 -0
- package/build/src/common-grpc/service.js +826 -0
- package/build/src/common.d.ts +66 -0
- package/build/src/common.js +54 -0
- package/build/src/database.d.ts +2103 -0
- package/build/src/database.js +1660 -0
- package/build/src/extra_proto_list.json +1 -0
- package/build/src/helper.d.ts +45 -0
- package/build/src/helper.js +71 -0
- package/build/src/index.d.ts +1195 -0
- package/build/src/index.js +1059 -0
- package/build/src/instance-config.d.ts +294 -0
- package/build/src/instance-config.js +216 -0
- package/build/src/instance.d.ts +832 -0
- package/build/src/instance.js +781 -0
- package/build/src/instrument.d.ts +85 -0
- package/build/src/instrument.js +215 -0
- package/build/src/multiplexed-session.d.ts +135 -0
- package/build/src/multiplexed-session.js +194 -0
- package/build/src/partial-result-stream.d.ts +253 -0
- package/build/src/partial-result-stream.js +400 -0
- package/build/src/request_id_header.d.ts +41 -0
- package/build/src/request_id_header.js +138 -0
- package/build/src/session-factory.d.ts +115 -0
- package/build/src/session-factory.js +106 -0
- package/build/src/session-pool.d.ts +471 -0
- package/build/src/session-pool.js +765 -0
- package/build/src/session.d.ts +258 -0
- package/build/src/session.js +348 -0
- package/build/src/spanner_grpc_config.json +92 -0
- package/build/src/table.d.ts +831 -0
- package/build/src/table.js +277 -0
- package/build/src/transaction-runner.d.ts +185 -0
- package/build/src/transaction-runner.js +282 -0
- package/build/src/transaction.d.ts +1691 -0
- package/build/src/transaction.js +2003 -0
- package/build/src/v1/database_admin_client.d.ts +2332 -0
- package/build/src/v1/database_admin_client.js +2364 -0
- package/build/src/v1/database_admin_client_config.json +165 -0
- package/build/src/v1/database_admin_proto_list.json +6 -0
- package/build/src/v1/gapic_metadata.json +27 -0
- package/build/src/v1/index.d.ts +4 -0
- package/build/src/v1/index.js +29 -0
- package/build/src/v1/instance_admin_client.d.ts +1985 -0
- package/build/src/v1/instance_admin_client.js +1768 -0
- package/build/src/v1/instance_admin_client_config.json +129 -0
- package/build/src/v1/instance_admin_proto_list.json +4 -0
- package/build/src/v1/spanner_client.d.ts +1250 -0
- package/build/src/v1/spanner_client.js +1086 -0
- package/build/src/v1/spanner_client_config.json +119 -0
- package/build/src/v1/spanner_executor_proxy_client.d.ts +418 -0
- package/build/src/v1/spanner_executor_proxy_client.js +706 -0
- package/build/src/v1/spanner_executor_proxy_client_config.json +30 -0
- package/build/src/v1/spanner_executor_proxy_proto_list.json +14 -0
- package/build/src/v1/spanner_proto_list.json +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright 2016 Google Inc. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/*!
|
|
17
|
+
* @module spanner/session
|
|
18
|
+
*/
|
|
19
|
+
declare const common: any;
|
|
20
|
+
import * as r from 'teeny-request';
|
|
21
|
+
import { Snapshot, Transaction, PartitionedDml, TimestampBounds } from './transaction';
|
|
22
|
+
import { google } from '../protos/protos';
|
|
23
|
+
import { Database } from './database';
|
|
24
|
+
import { NormalCallback } from './common';
|
|
25
|
+
import { grpc, CallOptions } from 'google-gax';
|
|
26
|
+
import IRequestOptions = google.spanner.v1.IRequestOptions;
|
|
27
|
+
export type GetSessionResponse = [Session, r.Response];
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated. enum to capture the possible session types
|
|
30
|
+
*/
|
|
31
|
+
export declare const enum types {
|
|
32
|
+
ReadOnly = "readonly",
|
|
33
|
+
ReadWrite = "readwrite"
|
|
34
|
+
}
|
|
35
|
+
export interface GetSessionMetadataResponse {
|
|
36
|
+
name?: string | null;
|
|
37
|
+
labels?: {
|
|
38
|
+
[k: string]: string;
|
|
39
|
+
} | null;
|
|
40
|
+
createTime?: google.protobuf.ITimestamp | null;
|
|
41
|
+
approximateLastUseTime?: google.protobuf.ITimestamp | null;
|
|
42
|
+
databaseRole?: string | null;
|
|
43
|
+
}
|
|
44
|
+
export type GetSessionMetadataCallback = NormalCallback<GetSessionMetadataResponse>;
|
|
45
|
+
export type KeepAliveCallback = NormalCallback<google.spanner.v1.IResultSet>;
|
|
46
|
+
export type KeepAliveResponse = [google.spanner.v1.IResultSet];
|
|
47
|
+
export type DeleteSessionResponse = [google.protobuf.IEmpty];
|
|
48
|
+
export type DeleteSessionCallback = NormalCallback<google.protobuf.IEmpty>;
|
|
49
|
+
/**
|
|
50
|
+
* Create a Session object to interact with a Cloud Spanner session.
|
|
51
|
+
*
|
|
52
|
+
* **It is unlikely you will need to interact with sessions directly. By
|
|
53
|
+
* default, sessions are created and utilized for maximum performance
|
|
54
|
+
* automatically.**
|
|
55
|
+
*
|
|
56
|
+
* @class
|
|
57
|
+
* @param {Database} database Parent {@link Database} instance.
|
|
58
|
+
* @param {string} [name] The name of the session. If not provided, it is
|
|
59
|
+
* assumed you are going to create it.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```
|
|
63
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
64
|
+
* const spanner = new Spanner();
|
|
65
|
+
*
|
|
66
|
+
* const instance = spanner.instance('my-instance');
|
|
67
|
+
* const database = instance.database('my-database');
|
|
68
|
+
*
|
|
69
|
+
* //-
|
|
70
|
+
* // To create a session manually, don't provide a name.
|
|
71
|
+
* //-
|
|
72
|
+
* const session = database.session();
|
|
73
|
+
*
|
|
74
|
+
* session.create(function(err) {
|
|
75
|
+
* if (err) {
|
|
76
|
+
* // Error handling omitted.
|
|
77
|
+
* }
|
|
78
|
+
*
|
|
79
|
+
* // Session created successfully.
|
|
80
|
+
* // `session.id` = The name of the session.
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* //-
|
|
84
|
+
* // To access a previously-created session, provide a name.
|
|
85
|
+
* //-
|
|
86
|
+
* const session = database.session('session-name');
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare class Session extends common.GrpcServiceObject {
|
|
90
|
+
id: string;
|
|
91
|
+
formattedName_?: string;
|
|
92
|
+
txn?: Transaction;
|
|
93
|
+
lastUsed?: number;
|
|
94
|
+
lastError?: grpc.ServiceError;
|
|
95
|
+
commonHeaders_: {
|
|
96
|
+
[k: string]: string;
|
|
97
|
+
};
|
|
98
|
+
constructor(database: Database, name?: string);
|
|
99
|
+
/**
|
|
100
|
+
* Delete a session.
|
|
101
|
+
*
|
|
102
|
+
* Wrapper around {@link v1.SpannerClient#deleteSession}.
|
|
103
|
+
*
|
|
104
|
+
* @see {@link v1.SpannerClient#deleteSession}
|
|
105
|
+
* @see [DeleteSession API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.DeleteSession)
|
|
106
|
+
*
|
|
107
|
+
* @param {object} [gaxOptions] Request configuration options,
|
|
108
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
109
|
+
* for more details.
|
|
110
|
+
* @param {DeleteSessionCallback} [callback] Callback function.
|
|
111
|
+
* @returns {Promise<DeleteSessionResponse>}
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```
|
|
115
|
+
* session.delete(function(err, apiResponse) {
|
|
116
|
+
* if (err) {
|
|
117
|
+
* // Error handling omitted.
|
|
118
|
+
* }
|
|
119
|
+
*
|
|
120
|
+
* // Session deleted successfully.
|
|
121
|
+
* });
|
|
122
|
+
*
|
|
123
|
+
* //-
|
|
124
|
+
* //Returns a Promise if the callback is omitted.
|
|
125
|
+
* //-
|
|
126
|
+
* session.delete().then(function(data) {
|
|
127
|
+
* const apiResponse = data[0];
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
delete(gaxOptions?: CallOptions): Promise<DeleteSessionResponse>;
|
|
132
|
+
delete(callback: DeleteSessionCallback): void;
|
|
133
|
+
delete(gaxOptions: CallOptions, callback: DeleteSessionCallback): void;
|
|
134
|
+
/**
|
|
135
|
+
* @typedef {array} GetSessionMetadataResponse
|
|
136
|
+
* @property {object} 0 The session's metadata.
|
|
137
|
+
* @property {object} 1 The full API response.
|
|
138
|
+
*/
|
|
139
|
+
/**
|
|
140
|
+
* @callback GetSessionMetadataCallback
|
|
141
|
+
* @param {?Error} err Request error, if any.
|
|
142
|
+
* @param {object} metadata The session's metadata.
|
|
143
|
+
* @param {object} apiResponse The full API response.
|
|
144
|
+
*/
|
|
145
|
+
/**
|
|
146
|
+
* Get the session's metadata.
|
|
147
|
+
*
|
|
148
|
+
* Wrapper around {@link v1.SpannerClient#getSession}.
|
|
149
|
+
*
|
|
150
|
+
* @see {@link v1.SpannerClient#getSession}
|
|
151
|
+
* @see [GetSession API Documentation](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Spanner.GetSession)
|
|
152
|
+
*
|
|
153
|
+
* @param {object} [gaxOptions] Request configuration options,
|
|
154
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
155
|
+
* for more details.
|
|
156
|
+
* @param {GetSessionMetadataCallback} [callback] Callback function.
|
|
157
|
+
* @returns {Promise<GetSessionMetadataResponse>}
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```
|
|
161
|
+
* session.getMetadata(function(err, metadata, apiResponse) {});
|
|
162
|
+
*
|
|
163
|
+
* //-
|
|
164
|
+
* //Returns a Promise if the callback is omitted.
|
|
165
|
+
* //-
|
|
166
|
+
* session.getMetadata().then(function(data) {
|
|
167
|
+
* const metadata = data[0];
|
|
168
|
+
* const apiResponse = data[1];
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
getMetadata(gaxOptions?: CallOptions): Promise<GetSessionMetadataResponse>;
|
|
173
|
+
getMetadata(callback: GetSessionMetadataCallback): void;
|
|
174
|
+
getMetadata(gaxOptions: CallOptions, callback: GetSessionMetadataCallback): void;
|
|
175
|
+
/**
|
|
176
|
+
* Ping the session with `SELECT 1` to prevent it from expiring.
|
|
177
|
+
*
|
|
178
|
+
* @param {object} [gaxOptions] Request configuration options,
|
|
179
|
+
* See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions}
|
|
180
|
+
* for more details.
|
|
181
|
+
* @param {BasicCallback} [callback] Callback function.
|
|
182
|
+
* @returns {Promise<BasicResponse>}
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```
|
|
186
|
+
* session.keepAlive(function(err) {
|
|
187
|
+
* if (err) {
|
|
188
|
+
* // An error occurred while trying to keep this session alive.
|
|
189
|
+
* }
|
|
190
|
+
* });
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
keepAlive(gaxOptions?: CallOptions): Promise<KeepAliveResponse>;
|
|
194
|
+
keepAlive(callback: KeepAliveCallback): void;
|
|
195
|
+
keepAlive(gaxOptions: CallOptions, callback: KeepAliveCallback): void;
|
|
196
|
+
/**
|
|
197
|
+
* Create a PartitionedDml transaction.
|
|
198
|
+
*
|
|
199
|
+
* @returns {PartitionedDml}
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```
|
|
203
|
+
* const transaction = session.partitionedDml();
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
partitionedDml(): PartitionedDml;
|
|
207
|
+
/**
|
|
208
|
+
* Create a Snapshot transaction.
|
|
209
|
+
*
|
|
210
|
+
* @param {TimestampBounds} [options] The timestamp bounds.
|
|
211
|
+
* @param {google.spanner.v1.ExecuteSqlRequest.IQueryOptions} [queryOptions] The default query options to use.
|
|
212
|
+
* @returns {Snapshot}
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```
|
|
216
|
+
* const snapshot = session.snapshot({strong: false});
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
snapshot(options?: TimestampBounds, queryOptions?: google.spanner.v1.ExecuteSqlRequest.IQueryOptions): Snapshot;
|
|
220
|
+
/**
|
|
221
|
+
* Create a read write Transaction.
|
|
222
|
+
*
|
|
223
|
+
* @param {google.spanner.v1.ExecuteSqlRequest.IQueryOptions} [queryOptions] The default query options to use.
|
|
224
|
+
* @return {Transaction}
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```
|
|
228
|
+
* const transaction = session.transaction();
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
transaction(queryOptions?: google.spanner.v1.ExecuteSqlRequest.IQueryOptions, requestOptions?: Pick<IRequestOptions, 'transactionTag'>): Transaction;
|
|
232
|
+
/**
|
|
233
|
+
* Format the session name to include the parent database's name.
|
|
234
|
+
*
|
|
235
|
+
* @private
|
|
236
|
+
*
|
|
237
|
+
* @param {string} databaseName The parent database's name.
|
|
238
|
+
* @param {string} name The instance name.
|
|
239
|
+
* @returns {string}
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```
|
|
243
|
+
* Session.formatName_('my-database', 'my-session');
|
|
244
|
+
* // 'projects/grape-spaceship-123/instances/my-instance/' +
|
|
245
|
+
* // 'databases/my-database/sessions/my-session'
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
static formatName_(databaseName: string, name: string): string;
|
|
249
|
+
/**
|
|
250
|
+
* Gets the Spanner object
|
|
251
|
+
*
|
|
252
|
+
* @private
|
|
253
|
+
*
|
|
254
|
+
* @returns {Spanner}
|
|
255
|
+
*/
|
|
256
|
+
private _getSpanner;
|
|
257
|
+
}
|
|
258
|
+
export {};
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright 2016 Google Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.Session = void 0;
|
|
19
|
+
/*!
|
|
20
|
+
* @module spanner/session
|
|
21
|
+
*/
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
23
|
+
const common = require('./common-grpc/service-object');
|
|
24
|
+
const promisify_1 = require("@google-cloud/promisify");
|
|
25
|
+
const extend = require("extend");
|
|
26
|
+
const transaction_1 = require("./transaction");
|
|
27
|
+
const common_1 = require("./common");
|
|
28
|
+
/**
|
|
29
|
+
* Create a Session object to interact with a Cloud Spanner session.
|
|
30
|
+
*
|
|
31
|
+
* **It is unlikely you will need to interact with sessions directly. By
|
|
32
|
+
* default, sessions are created and utilized for maximum performance
|
|
33
|
+
* automatically.**
|
|
34
|
+
*
|
|
35
|
+
* @class
|
|
36
|
+
* @param {Database} database Parent {@link Database} instance.
|
|
37
|
+
* @param {string} [name] The name of the session. If not provided, it is
|
|
38
|
+
* assumed you are going to create it.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```
|
|
42
|
+
* const {Spanner} = require('@google-cloud/spanner');
|
|
43
|
+
* const spanner = new Spanner();
|
|
44
|
+
*
|
|
45
|
+
* const instance = spanner.instance('my-instance');
|
|
46
|
+
* const database = instance.database('my-database');
|
|
47
|
+
*
|
|
48
|
+
* //-
|
|
49
|
+
* // To create a session manually, don't provide a name.
|
|
50
|
+
* //-
|
|
51
|
+
* const session = database.session();
|
|
52
|
+
*
|
|
53
|
+
* session.create(function(err) {
|
|
54
|
+
* if (err) {
|
|
55
|
+
* // Error handling omitted.
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* // Session created successfully.
|
|
59
|
+
* // `session.id` = The name of the session.
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* //-
|
|
63
|
+
* // To access a previously-created session, provide a name.
|
|
64
|
+
* //-
|
|
65
|
+
* const session = database.session('session-name');
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
class Session extends common.GrpcServiceObject {
|
|
69
|
+
constructor(database, name) {
|
|
70
|
+
var _a;
|
|
71
|
+
const methods = {
|
|
72
|
+
/**
|
|
73
|
+
* Create a session.
|
|
74
|
+
*
|
|
75
|
+
* @method Session#create
|
|
76
|
+
* @param {object} [options] See {@link Database#createSession}.
|
|
77
|
+
* @param {CreateSessionCallback} [callback] Callback function.
|
|
78
|
+
* @returns {Promise<CreateSessionResponse>}
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```
|
|
82
|
+
* session.create(function(err, session, apiResponse) {
|
|
83
|
+
* if (err) {
|
|
84
|
+
* // Error handling omitted.
|
|
85
|
+
* }
|
|
86
|
+
*
|
|
87
|
+
* // Session created successfully.
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* //-
|
|
91
|
+
* //Returns a Promise if the callback is omitted.
|
|
92
|
+
* //-
|
|
93
|
+
* session.create()
|
|
94
|
+
* .then(function(data) {
|
|
95
|
+
* const session = data[0];
|
|
96
|
+
* const apiResponse = data[1];
|
|
97
|
+
*
|
|
98
|
+
* // Session created successfully.
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
create: true,
|
|
103
|
+
/**
|
|
104
|
+
* @typedef {array} SessionExistsResponse
|
|
105
|
+
* @property {boolean} 0 Whether the {@link Session} exists.
|
|
106
|
+
*/
|
|
107
|
+
/**
|
|
108
|
+
* @callback SessionExistsCallback
|
|
109
|
+
* @param {?Error} err Request error, if any.
|
|
110
|
+
* @param {boolean} exists Whether the {@link Session} exists.
|
|
111
|
+
*/
|
|
112
|
+
/**
|
|
113
|
+
* Check if a session exists.
|
|
114
|
+
*
|
|
115
|
+
* @method Session#exists
|
|
116
|
+
* @param {SessionExistsCallback} [callback] Callback function.
|
|
117
|
+
* @returns {Promise<SessionExistsResponse>}
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```
|
|
121
|
+
* session.exists(function(err, exists) {});
|
|
122
|
+
*
|
|
123
|
+
* //-
|
|
124
|
+
* //Returns a Promise if the callback is omitted.
|
|
125
|
+
* //-
|
|
126
|
+
* session.exists().then(function(data) {
|
|
127
|
+
* const exists = data[0];
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
exists: true,
|
|
132
|
+
/**
|
|
133
|
+
* @typedef {array} GetSessionResponse
|
|
134
|
+
* @property {Session} 0 The {@link Session}.
|
|
135
|
+
* @property {object} 1 The full API response.
|
|
136
|
+
*/
|
|
137
|
+
/**
|
|
138
|
+
* @callback CreateSessionCallback
|
|
139
|
+
* @param {?Error} err Request error, if any.
|
|
140
|
+
* @param {Session} session The {@link Session}.
|
|
141
|
+
* @param {object} apiResponse The full API response.
|
|
142
|
+
*/
|
|
143
|
+
/**
|
|
144
|
+
* Get a session if it exists.
|
|
145
|
+
*
|
|
146
|
+
* You may optionally use this to "get or create" an object by providing
|
|
147
|
+
* an object with `autoCreate` set to `true`. Any extra configuration that
|
|
148
|
+
* is normally required for the `create` method must be contained within
|
|
149
|
+
* this object as well.
|
|
150
|
+
*
|
|
151
|
+
* @method Session#get
|
|
152
|
+
* @param {options} [options] Configuration object.
|
|
153
|
+
* @param {boolean} [options.autoCreate=false] Automatically create the
|
|
154
|
+
* object if it does not exist.
|
|
155
|
+
* @param {CreateSessionCallback} [callback] Callback function.
|
|
156
|
+
* @returns {Promise<GetSessionResponse>}
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```
|
|
160
|
+
* session.get(function(err, session, apiResponse) {
|
|
161
|
+
* // `session.metadata` has been populated.
|
|
162
|
+
* });
|
|
163
|
+
*
|
|
164
|
+
* //-
|
|
165
|
+
* //Returns a Promise if the callback is omitted.
|
|
166
|
+
* //-
|
|
167
|
+
* session.get().then(function(data) {
|
|
168
|
+
* const session = data[0];
|
|
169
|
+
* const apiResponse = data[0];
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
get: true,
|
|
174
|
+
};
|
|
175
|
+
super({
|
|
176
|
+
parent: database,
|
|
177
|
+
/**
|
|
178
|
+
* @name Session#id
|
|
179
|
+
* @type {string}
|
|
180
|
+
*/
|
|
181
|
+
id: name,
|
|
182
|
+
methods,
|
|
183
|
+
createMethod: (_, optionsOrCallback, callback) => {
|
|
184
|
+
const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
185
|
+
callback =
|
|
186
|
+
typeof optionsOrCallback === 'function'
|
|
187
|
+
? optionsOrCallback
|
|
188
|
+
: callback;
|
|
189
|
+
this.labels = options.labels || null;
|
|
190
|
+
this.databaseRole =
|
|
191
|
+
options.databaseRole || database.databaseRole || null;
|
|
192
|
+
return database.createSession(options, (err, session, apiResponse) => {
|
|
193
|
+
if (err) {
|
|
194
|
+
callback(err, null, apiResponse);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
extend(this, session);
|
|
198
|
+
callback(null, this, apiResponse);
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
this.commonHeaders_ = (0, common_1.getCommonHeaders)(this.parent.formattedName_, (_a = database._observabilityOptions) === null || _a === void 0 ? void 0 : _a.enableEndToEndTracing);
|
|
203
|
+
this.request = database.request;
|
|
204
|
+
this.requestStream = database.requestStream;
|
|
205
|
+
if (name) {
|
|
206
|
+
this.formattedName_ = Session.formatName_(database.formattedName_, name);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
delete(optionsOrCallback, cb) {
|
|
210
|
+
const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
211
|
+
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
212
|
+
const reqOpts = {
|
|
213
|
+
name: this.formattedName_,
|
|
214
|
+
};
|
|
215
|
+
return this.request({
|
|
216
|
+
client: 'SpannerClient',
|
|
217
|
+
method: 'deleteSession',
|
|
218
|
+
reqOpts,
|
|
219
|
+
gaxOpts,
|
|
220
|
+
headers: this.commonHeaders_,
|
|
221
|
+
}, callback);
|
|
222
|
+
}
|
|
223
|
+
getMetadata(optionsOrCallback, cb) {
|
|
224
|
+
const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
225
|
+
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
226
|
+
const reqOpts = {
|
|
227
|
+
name: this.formattedName_,
|
|
228
|
+
};
|
|
229
|
+
const headers = this.commonHeaders_;
|
|
230
|
+
if (this._getSpanner().routeToLeaderEnabled) {
|
|
231
|
+
(0, common_1.addLeaderAwareRoutingHeader)(headers);
|
|
232
|
+
}
|
|
233
|
+
return this.request({
|
|
234
|
+
client: 'SpannerClient',
|
|
235
|
+
method: 'getSession',
|
|
236
|
+
reqOpts,
|
|
237
|
+
gaxOpts,
|
|
238
|
+
headers: headers,
|
|
239
|
+
}, (err, resp) => {
|
|
240
|
+
if (resp) {
|
|
241
|
+
resp.databaseRole = resp.creatorRole;
|
|
242
|
+
delete resp.creatorRole;
|
|
243
|
+
this.metadata = resp;
|
|
244
|
+
}
|
|
245
|
+
callback(err, resp);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
keepAlive(optionsOrCallback, cb) {
|
|
249
|
+
const gaxOpts = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
|
250
|
+
const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
|
251
|
+
const reqOpts = {
|
|
252
|
+
session: this.formattedName_,
|
|
253
|
+
sql: 'SELECT 1',
|
|
254
|
+
};
|
|
255
|
+
return this.request({
|
|
256
|
+
client: 'SpannerClient',
|
|
257
|
+
method: 'executeSql',
|
|
258
|
+
reqOpts,
|
|
259
|
+
gaxOpts,
|
|
260
|
+
headers: this.commonHeaders_,
|
|
261
|
+
}, callback);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Create a PartitionedDml transaction.
|
|
265
|
+
*
|
|
266
|
+
* @returns {PartitionedDml}
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```
|
|
270
|
+
* const transaction = session.partitionedDml();
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
partitionedDml() {
|
|
274
|
+
return new transaction_1.PartitionedDml(this);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Create a Snapshot transaction.
|
|
278
|
+
*
|
|
279
|
+
* @param {TimestampBounds} [options] The timestamp bounds.
|
|
280
|
+
* @param {google.spanner.v1.ExecuteSqlRequest.IQueryOptions} [queryOptions] The default query options to use.
|
|
281
|
+
* @returns {Snapshot}
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```
|
|
285
|
+
* const snapshot = session.snapshot({strong: false});
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
snapshot(options, queryOptions) {
|
|
289
|
+
return new transaction_1.Snapshot(this, options, queryOptions);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Create a read write Transaction.
|
|
293
|
+
*
|
|
294
|
+
* @param {google.spanner.v1.ExecuteSqlRequest.IQueryOptions} [queryOptions] The default query options to use.
|
|
295
|
+
* @return {Transaction}
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```
|
|
299
|
+
* const transaction = session.transaction();
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
transaction(queryOptions, requestOptions) {
|
|
303
|
+
return new transaction_1.Transaction(this, undefined, queryOptions, requestOptions);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Format the session name to include the parent database's name.
|
|
307
|
+
*
|
|
308
|
+
* @private
|
|
309
|
+
*
|
|
310
|
+
* @param {string} databaseName The parent database's name.
|
|
311
|
+
* @param {string} name The instance name.
|
|
312
|
+
* @returns {string}
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```
|
|
316
|
+
* Session.formatName_('my-database', 'my-session');
|
|
317
|
+
* // 'projects/grape-spaceship-123/instances/my-instance/' +
|
|
318
|
+
* // 'databases/my-database/sessions/my-session'
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
static formatName_(databaseName, name) {
|
|
322
|
+
if (name.indexOf('/') > -1) {
|
|
323
|
+
return name;
|
|
324
|
+
}
|
|
325
|
+
const sessionName = name.split('/').pop();
|
|
326
|
+
return databaseName + '/sessions/' + sessionName;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Gets the Spanner object
|
|
330
|
+
*
|
|
331
|
+
* @private
|
|
332
|
+
*
|
|
333
|
+
* @returns {Spanner}
|
|
334
|
+
*/
|
|
335
|
+
_getSpanner() {
|
|
336
|
+
return this.parent.parent.parent;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
exports.Session = Session;
|
|
340
|
+
/*! Developer Documentation
|
|
341
|
+
*
|
|
342
|
+
* All async methods (except for streams) will return a Promise in the event
|
|
343
|
+
* that a callback is omitted.
|
|
344
|
+
*/
|
|
345
|
+
(0, promisify_1.promisifyAll)(Session, {
|
|
346
|
+
exclude: ['delete', 'partitionedDml', 'snapshot', 'transaction'],
|
|
347
|
+
});
|
|
348
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"channelPool": {
|
|
3
|
+
"maxSize": 10,
|
|
4
|
+
"maxConcurrentStreamsLowWatermark": 100
|
|
5
|
+
},
|
|
6
|
+
"method": [
|
|
7
|
+
{
|
|
8
|
+
"name": ["/google.spanner.v1.Spanner/CreateSession"],
|
|
9
|
+
"affinity": {
|
|
10
|
+
"command": "BIND",
|
|
11
|
+
"affinityKey": "name"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": ["/google.spanner.v1.Spanner/GetSession"],
|
|
16
|
+
"affinity": {
|
|
17
|
+
"command": "BOUND",
|
|
18
|
+
"affinityKey": "name"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"name": ["/google.spanner.v1.Spanner/DeleteSession"],
|
|
23
|
+
"affinity": {
|
|
24
|
+
"command": "UNBIND",
|
|
25
|
+
"affinityKey": "name"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": ["/google.spanner.v1.Spanner/ExecuteSql"],
|
|
30
|
+
"affinity": {
|
|
31
|
+
"command": "BOUND",
|
|
32
|
+
"affinityKey": "session"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": ["/google.spanner.v1.Spanner/ExecuteStreamingSql"],
|
|
37
|
+
"affinity": {
|
|
38
|
+
"command": "BOUND",
|
|
39
|
+
"affinityKey": "session"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"name": ["/google.spanner.v1.Spanner/Read"],
|
|
44
|
+
"affinity": {
|
|
45
|
+
"command": "BOUND",
|
|
46
|
+
"affinityKey": "session"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": ["/google.spanner.v1.Spanner/StreamingRead"],
|
|
51
|
+
"affinity": {
|
|
52
|
+
"command": "BOUND",
|
|
53
|
+
"affinityKey": "session"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": ["/google.spanner.v1.Spanner/BeginTransaction"],
|
|
58
|
+
"affinity": {
|
|
59
|
+
"command": "BOUND",
|
|
60
|
+
"affinityKey": "session"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"name": ["/google.spanner.v1.Spanner/Commit"],
|
|
65
|
+
"affinity": {
|
|
66
|
+
"command": "BOUND",
|
|
67
|
+
"affinityKey": "session"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"name": ["/google.spanner.v1.Spanner/Rollback"],
|
|
72
|
+
"affinity": {
|
|
73
|
+
"command": "BOUND",
|
|
74
|
+
"affinityKey": "session"
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"name": ["/google.spanner.v1.Spanner/PartitionQuery"],
|
|
79
|
+
"affinity": {
|
|
80
|
+
"command": "BOUND",
|
|
81
|
+
"affinityKey": "session"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"name": ["/google.spanner.v1.Spanner/PartitionRead"],
|
|
86
|
+
"affinity": {
|
|
87
|
+
"command": "BOUND",
|
|
88
|
+
"affinityKey": "session"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|