1
- import { Ydb } from "ydb-sdk-proto" ;
1
+ import { Ydb } from "ydb-sdk-proto" ;
2
2
import {
3
3
isIdempotentDoLevelSymbol ,
4
4
isIdempotentSymbol ,
5
5
resultsetYdbColumnsSymbol ,
6
6
sessionCurrentOperationSymbol ,
7
+ sessionTrailerCallbackSymbol ,
7
8
sessionTxIdSymbol ,
8
9
sessionTxSettingsSymbol ,
9
10
} from "./symbols" ;
10
- import { buildAsyncQueueIterator , IAsyncQueueIterator } from "../utils/build-async-queue-iterator" ;
11
- import { ResultSet } from "./result-set" ;
12
- import { ClientReadableStream } from "@grpc/grpc-js" ;
13
- import { ensureCallSucceeded } from "../utils/process-ydb-operation-result" ;
11
+ import { buildAsyncQueueIterator , IAsyncQueueIterator } from "../utils/build-async-queue-iterator" ;
12
+ import { ResultSet } from "./result-set" ;
13
+ import { ClientReadableStream } from "@grpc/grpc-js" ;
14
+ import { ensureCallSucceeded } from "../utils/process-ydb-operation-result" ;
14
15
import Long from "long" ;
15
- import { StatusObject as GrpcStatusObject } from "@grpc/grpc-js/build/src/call-interface" ;
16
- import { TransportError } from "../errors" ;
17
- import { implSymbol , QuerySession } from "./query-session" ;
18
- import { convertYdbValueToNative , snakeToCamelCaseConversion } from "../types" ;
19
- import { CtxUnsubcribe } from "../context" ;
16
+ import { StatusObject as GrpcStatusObject } from "@grpc/grpc-js/build/src/call-interface" ;
17
+ import { TransportError } from "../errors" ;
18
+ import { implSymbol , QuerySession } from "./query-session" ;
19
+ import { convertYdbValueToNative , snakeToCamelCaseConversion } from "../types" ;
20
+ import { CtxUnsubcribe } from "../context" ;
20
21
import IExecuteQueryRequest = Ydb . Query . IExecuteQueryRequest ;
21
22
import IColumn = Ydb . IColumn ;
22
23
@@ -113,7 +114,7 @@ export function execute(this: QuerySession, args: IExecuteArgs): Promise<IExecut
113
114
throw new Error ( 'txControl.commitTx === true when no open transaction and there\'s no txControl.beginTx' ) ;
114
115
}
115
116
116
- // Build params
117
+ // Build params
117
118
const executeQueryRequest : IExecuteQueryRequest = {
118
119
sessionId : this . sessionId ,
119
120
queryContent : {
@@ -126,7 +127,7 @@ export function execute(this: QuerySession, args: IExecuteArgs): Promise<IExecut
126
127
if ( args . statsMode ) executeQueryRequest . statsMode = args . statsMode ;
127
128
if ( args . parameters ) executeQueryRequest . parameters = args . parameters ;
128
129
if ( this [ sessionTxSettingsSymbol ] && ! this [ sessionTxIdSymbol ] )
129
- executeQueryRequest . txControl = { beginTx : this [ sessionTxSettingsSymbol ] , commitTx : false } ;
130
+ executeQueryRequest . txControl = { beginTx : this [ sessionTxSettingsSymbol ] , commitTx : false } ;
130
131
else if ( args . txControl )
131
132
executeQueryRequest . txControl = args . txControl ;
132
133
if ( this [ sessionTxIdSymbol ] )
@@ -137,7 +138,7 @@ export function execute(this: QuerySession, args: IExecuteArgs): Promise<IExecut
137
138
if ( args . idempotent ) this [ isIdempotentSymbol ] = true ;
138
139
}
139
140
140
- // Run the operation
141
+ // Run the operation
141
142
let finished = false ;
142
143
const resultSetByIndex : [ iterator : IAsyncQueueIterator < Ydb . IValue > , resultSet : ResultSet ] [ ] = [ ] ;
143
144
const resultSetIterator = buildAsyncQueueIterator < ResultSet > ( ) ;
@@ -158,7 +159,7 @@ export function execute(this: QuerySession, args: IExecuteArgs): Promise<IExecut
158
159
} ) ;
159
160
}
160
161
161
- // One operation per session in a time. And it might be cancelled
162
+ // One operation per session in a time. And it might be cancelled
162
163
if ( this [ sessionCurrentOperationSymbol ] ) throw new Error ( 'There\'s another active operation in the session' ) ;
163
164
164
165
const cancel = ( reason : any , onStreamError ?: boolean ) => {
@@ -179,9 +180,9 @@ export function execute(this: QuerySession, args: IExecuteArgs): Promise<IExecut
179
180
delete this [ sessionCurrentOperationSymbol ] ;
180
181
}
181
182
182
- this [ sessionCurrentOperationSymbol ] = { cancel} ;
183
+ this [ sessionCurrentOperationSymbol ] = { cancel } ;
183
184
184
- // Operation
185
+ // Operation
185
186
responseStream = this [ implSymbol ] . grpcServiceClient ! . makeServerStreamRequest (
186
187
'/Ydb.Query.V1.QueryService/ExecuteQuery' ,
187
188
( v ) => Ydb . Query . ExecuteQueryRequest . encode ( v ) . finish ( ) as Buffer ,
@@ -282,7 +283,11 @@ export function execute(this: QuerySession, args: IExecuteArgs): Promise<IExecut
282
283
cancel ( TransportError . convertToYdbError ( err ) , true ) ;
283
284
} ) ;
284
285
285
- responseStream . on ( 'metadata' , ( _metadata ) => {
286
+ responseStream . on ( 'metadata' , ( metadata ) => {
287
+ if ( this [ sessionTrailerCallbackSymbol ] ) {
288
+ this [ sessionTrailerCallbackSymbol ] ( metadata ) ;
289
+ }
290
+
286
291
// TODO: Process partial meta
287
292
// TODO: Expect to see on graceful shutdown
288
293
} ) ;
0 commit comments