@@ -57,11 +57,6 @@ const slice = createSlice({
5757 }
5858 } ,
5959 setQueryResult : ( state , action : PayloadAction < QueryResult | undefined > ) => {
60- console . log ( '[QueryState] Setting query result:' , {
61- type : action . payload ?. type ,
62- isLoading : action . payload ?. isLoading ,
63- hasError : Boolean ( action . payload ?. error ) ,
64- } ) ;
6560 state . result = action . payload ;
6661 } ,
6762 saveQueryToHistory : (
@@ -235,7 +230,6 @@ interface SendQueryParams extends QueryRequestParams {
235230 // flag whether to send new tracing header or not
236231 // default: not send
237232 enableTracingLevel ?: boolean ;
238- isStreaming ?: boolean ;
239233}
240234
241235interface QueryStats {
@@ -245,6 +239,65 @@ interface QueryStats {
245239
246240export const queryApi = api . injectEndpoints ( {
247241 endpoints : ( build ) => ( {
242+ useStreamQuery : build . mutation < null , SendQueryParams > ( {
243+ queryFn : async (
244+ { query, database, querySettings = { } , enableTracingLevel, queryId} ,
245+ { signal, dispatch} ,
246+ ) => {
247+ dispatch ( setQueryResult ( { type : 'execute' , queryId, isLoading : true } ) ) ;
248+ dispatch ( setStreamingState ( true ) ) ;
249+
250+ const { action, syntax} = getActionAndSyntaxFromQueryMode (
251+ 'execute' ,
252+ querySettings ?. queryMode ,
253+ ) ;
254+
255+ try {
256+ await window . api . viewer . streamQuery (
257+ {
258+ query,
259+ database,
260+ action,
261+ syntax,
262+ stats : querySettings . statisticsMode ,
263+ tracingLevel :
264+ querySettings . tracingLevel && enableTracingLevel
265+ ? TracingLevelNumber [ querySettings . tracingLevel ]
266+ : undefined ,
267+ limit_rows : isNumeric ( querySettings . limitRows )
268+ ? Number ( querySettings . limitRows )
269+ : undefined ,
270+ transaction_mode :
271+ querySettings . transactionMode === 'implicit'
272+ ? undefined
273+ : querySettings . transactionMode ,
274+ timeout : isNumeric ( querySettings . timeout )
275+ ? Number ( querySettings . timeout ) * 1000
276+ : undefined ,
277+ output_chunk_max_size : 10 ,
278+ } ,
279+ {
280+ signal,
281+ onChunk : ( chunk ) => {
282+ dispatch ( addStreamingChunk ( chunk ) ) ;
283+ } ,
284+ } ,
285+ ) ;
286+
287+ return { data : null } ;
288+ } catch ( error ) {
289+ dispatch (
290+ setQueryResult ( {
291+ type : 'execute' ,
292+ error,
293+ isLoading : false ,
294+ queryId,
295+ } ) ,
296+ ) ;
297+ return { error} ;
298+ }
299+ } ,
300+ } ) ,
248301 useSendQuery : build . mutation < null , SendQueryParams > ( {
249302 queryFn : async (
250303 {
@@ -254,7 +307,6 @@ export const queryApi = api.injectEndpoints({
254307 querySettings = { } ,
255308 enableTracingLevel,
256309 queryId,
257- isStreaming,
258310 } ,
259311 { signal, dispatch} ,
260312 ) => {
@@ -267,44 +319,6 @@ export const queryApi = api.injectEndpoints({
267319 ) ;
268320
269321 try {
270- if ( isStreaming && actionType === 'execute' ) {
271- dispatch ( setStreamingState ( true ) ) ;
272-
273- await window . api . viewer . streamQuery (
274- {
275- query,
276- database,
277- action,
278- syntax,
279- stats : querySettings . statisticsMode ,
280- tracingLevel :
281- querySettings . tracingLevel && enableTracingLevel
282- ? TracingLevelNumber [ querySettings . tracingLevel ]
283- : undefined ,
284- limit_rows : isNumeric ( querySettings . limitRows )
285- ? Number ( querySettings . limitRows )
286- : undefined ,
287- transaction_mode :
288- querySettings . transactionMode === 'implicit'
289- ? undefined
290- : querySettings . transactionMode ,
291- timeout : isNumeric ( querySettings . timeout )
292- ? Number ( querySettings . timeout ) * 1000
293- : undefined ,
294- output_chunk_max_size : 10 ,
295- } ,
296- {
297- signal,
298- onChunk : ( chunk ) => {
299- dispatch ( addStreamingChunk ( chunk ) ) ;
300- } ,
301- } ,
302- ) ;
303-
304- return { data : null } ;
305- }
306-
307- // Legacy implementation for older versions and non-execute queries
308322 const response = await window . api . viewer . sendQuery (
309323 {
310324 query,
0 commit comments