File tree Expand file tree Collapse file tree 4 files changed +34
-45
lines changed
Expand file tree Collapse file tree 4 files changed +34
-45
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " slonik " : patch
3+ ---
4+
5+ reduce microtasks
Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ import type {
77 QueryResultRow ,
88} from '../types.js' ;
99import type { DriverNotice , DriverQueryResult } from '@slonik/driver' ;
10- import { SlonikError } from '@slonik/errors' ;
1110
1211const executionRoutine : ExecutionRoutine = async (
1312 finalConnection ,
@@ -42,30 +41,22 @@ const executionRoutine: ExecutionRoutine = async (
4241 } ;
4342} ;
4443
45- export const query : InternalQueryMethod = async (
44+ export const query : InternalQueryMethod = (
4645 connectionLogger ,
4746 connection ,
4847 clientConfiguration ,
4948 slonikSql ,
5049 inheritedQueryId ,
5150 integrityValidation ,
5251) => {
53- try {
54- return await executeQuery (
55- connectionLogger ,
56- connection ,
57- clientConfiguration ,
58- slonikSql ,
59- inheritedQueryId ,
60- executionRoutine ,
61- false ,
62- integrityValidation ,
63- ) ;
64- } catch ( error ) {
65- if ( error instanceof SlonikError ) {
66- connection . events . emit ( 'error' , error ) ;
67- }
68-
69- throw error ;
70- }
52+ return executeQuery (
53+ connectionLogger ,
54+ connection ,
55+ clientConfiguration ,
56+ slonikSql ,
57+ inheritedQueryId ,
58+ executionRoutine ,
59+ false ,
60+ integrityValidation ,
61+ ) ;
7162} ;
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ import type {
1010 StreamHandler ,
1111} from '../types.js' ;
1212import type { DriverStreamResult } from '@slonik/driver' ;
13- import { SlonikError } from '@slonik/errors' ;
1413import { Transform } from 'node:stream' ;
1514import { pipeline } from 'node:stream/promises' ;
1615
@@ -148,29 +147,19 @@ export const stream: InternalStreamFunction = async (
148147 onStream ,
149148 uid ,
150149) => {
151- try {
152- const result = await executeQuery (
153- connectionLogger ,
154- connection ,
155- clientConfiguration ,
156- slonikSql ,
157- uid ,
158- createExecutionRoutine ( clientConfiguration , onStream ) ,
159- true ,
160- ) ;
161-
162- if ( result . type === 'QueryResult' ) {
163- throw new Error (
164- 'Query result cannot be returned in a streaming context.' ,
165- ) ;
166- }
167-
168- return result ;
169- } catch ( error ) {
170- if ( error instanceof SlonikError ) {
171- connection . events . emit ( 'error' , error ) ;
172- }
173-
174- throw error ;
150+ const result = await executeQuery (
151+ connectionLogger ,
152+ connection ,
153+ clientConfiguration ,
154+ slonikSql ,
155+ uid ,
156+ createExecutionRoutine ( clientConfiguration , onStream ) ,
157+ true ,
158+ ) ;
159+
160+ if ( result . type === 'QueryResult' ) {
161+ throw new Error ( 'Query result cannot be returned in a streaming context.' ) ;
175162 }
163+
164+ return result ;
176165} ;
Original file line number Diff line number Diff line change @@ -711,6 +711,10 @@ export const executeQuery = async (
711711 stream ,
712712 ) ;
713713 } catch ( error ) {
714+ if ( error instanceof SlonikError ) {
715+ connection . events . emit ( 'error' , error ) ;
716+ }
717+
714718 span . recordException ( error ) ;
715719 span . setStatus ( {
716720 code : SpanStatusCode . ERROR ,
You can’t perform that action at this time.
0 commit comments