@@ -187,132 +187,108 @@ export class MysqlQueryRunner extends BaseQueryRunner implements QueryRunner {
187
187
) : Promise < any > {
188
188
if ( this . isReleased ) throw new QueryRunnerAlreadyReleasedError ( )
189
189
190
- return new Promise ( async ( ok , fail ) => {
191
- const databaseConnection = await this . connect ( )
190
+ const databaseConnection = await this . connect ( )
192
191
193
- this . driver . connection . logger . logQuery ( query , parameters , this )
194
- await this . broadcaster . broadcast ( "BeforeQuery" , query , parameters )
192
+ this . driver . connection . logger . logQuery ( query , parameters , this )
193
+ await this . broadcaster . broadcast ( "BeforeQuery" , query , parameters )
195
194
196
- const broadcasterResult = new BroadcasterResult ( )
197
- const queryStartTime = Date . now ( )
195
+ const broadcasterResult = new BroadcasterResult ( )
196
+ const queryStartTime = Date . now ( )
198
197
199
- try {
200
- const enableQueryTimeout =
201
- this . driver . options . enableQueryTimeout
202
- const maxQueryExecutionTime =
203
- this . driver . options . maxQueryExecutionTime
204
- const queryPayload =
205
- enableQueryTimeout && maxQueryExecutionTime
206
- ? { sql : query , timeout : maxQueryExecutionTime }
207
- : query
208
- databaseConnection . query (
209
- queryPayload ,
198
+ try {
199
+ const enableQueryTimeout = this . driver . options . enableQueryTimeout
200
+ // log slow queries if maxQueryExecution time is set
201
+ const maxQueryExecutionTime =
202
+ this . driver . options . maxQueryExecutionTime
203
+ const queryPayload =
204
+ enableQueryTimeout && maxQueryExecutionTime
205
+ ? { sql : query , timeout : maxQueryExecutionTime }
206
+ : query
207
+ const raw = databaseConnection . query ( queryPayload , parameters )
208
+
209
+ const queryEndTime = Date . now ( )
210
+ const queryExecutionTime = queryEndTime - queryStartTime
211
+
212
+ if (
213
+ maxQueryExecutionTime &&
214
+ queryExecutionTime > maxQueryExecutionTime
215
+ )
216
+ this . driver . connection . logger . logQuerySlow (
217
+ queryExecutionTime ,
218
+ query ,
210
219
parameters ,
211
- async ( err : any , raw : any ) => {
212
- // log slow queries if maxQueryExecution time is set
213
- const maxQueryExecutionTime =
214
- this . driver . options . maxQueryExecutionTime
215
- const queryEndTime = Date . now ( )
216
- const queryExecutionTime = queryEndTime - queryStartTime
217
-
218
- if (
219
- maxQueryExecutionTime &&
220
- queryExecutionTime > maxQueryExecutionTime
221
- )
222
- this . driver . connection . logger . logQuerySlow (
223
- queryExecutionTime ,
224
- query ,
225
- parameters ,
226
- this ,
227
- )
228
-
229
- if ( err ) {
230
- this . driver . connection . logger . logQueryError (
231
- err ,
232
- query ,
233
- parameters ,
234
- this ,
235
- )
236
- this . broadcaster . broadcastAfterQueryEvent (
237
- broadcasterResult ,
238
- query ,
239
- parameters ,
240
- false ,
241
- undefined ,
242
- undefined ,
243
- err ,
244
- )
245
-
246
- return fail (
247
- new QueryFailedError ( query , parameters , err ) ,
248
- )
249
- }
220
+ this ,
221
+ )
250
222
251
- this . broadcaster . broadcastAfterQueryEvent (
252
- broadcasterResult ,
253
- query ,
254
- parameters ,
255
- true ,
256
- queryExecutionTime ,
257
- raw ,
258
- undefined ,
259
- )
223
+ this . broadcaster . broadcastAfterQueryEvent (
224
+ broadcasterResult ,
225
+ query ,
226
+ parameters ,
227
+ true ,
228
+ queryExecutionTime ,
229
+ raw ,
230
+ undefined ,
231
+ )
260
232
261
- const result = new QueryResult ( )
233
+ const result = new QueryResult ( )
262
234
263
- result . raw = raw
235
+ result . raw = raw
264
236
265
- try {
266
- result . records = Array . from ( raw )
267
- } catch {
268
- // Do nothing.
269
- }
237
+ try {
238
+ result . records = Array . from ( raw )
239
+ } catch {
240
+ // Do nothing.
241
+ }
270
242
271
- if ( raw ?. hasOwnProperty ( "affectedRows" ) ) {
272
- result . affected = raw . affectedRows
273
- }
243
+ if ( raw ?. hasOwnProperty ( "affectedRows" ) ) {
244
+ result . affected = raw . affectedRows
245
+ }
274
246
275
- if ( useStructuredResult ) {
276
- ok ( result )
277
- } else {
278
- ok ( result . raw )
279
- }
280
- } ,
281
- )
282
- } catch ( err ) {
283
- fail ( err )
284
- } finally {
285
- await broadcasterResult . wait ( )
247
+ if ( useStructuredResult ) {
248
+ return result
249
+ } else {
250
+ return result . raw
286
251
}
287
- } )
252
+ } catch ( err ) {
253
+ this . driver . connection . logger . logQueryError (
254
+ err ,
255
+ query ,
256
+ parameters ,
257
+ this ,
258
+ )
259
+ this . broadcaster . broadcastAfterQueryEvent (
260
+ broadcasterResult ,
261
+ query ,
262
+ parameters ,
263
+ false ,
264
+ undefined ,
265
+ undefined ,
266
+ err ,
267
+ )
268
+
269
+ throw new QueryFailedError ( query , parameters , err )
270
+ } finally {
271
+ await broadcasterResult . wait ( )
272
+ }
288
273
}
289
274
290
275
/**
291
276
* Returns raw data stream.
292
277
*/
293
- stream (
278
+ async stream (
294
279
query : string ,
295
280
parameters ?: any [ ] ,
296
281
onEnd ?: Function ,
297
282
onError ?: Function ,
298
283
) : Promise < ReadStream > {
299
284
if ( this . isReleased ) throw new QueryRunnerAlreadyReleasedError ( )
300
285
301
- return new Promise ( async ( ok , fail ) => {
302
- try {
303
- const databaseConnection = await this . connect ( )
304
- this . driver . connection . logger . logQuery ( query , parameters , this )
305
- const databaseQuery = databaseConnection . query (
306
- query ,
307
- parameters ,
308
- )
309
- if ( onEnd ) databaseQuery . on ( "end" , onEnd )
310
- if ( onError ) databaseQuery . on ( "error" , onError )
311
- ok ( databaseQuery . stream ( ) )
312
- } catch ( err ) {
313
- fail ( err )
314
- }
315
- } )
286
+ const databaseConnection = await this . connect ( )
287
+ this . driver . connection . logger . logQuery ( query , parameters , this )
288
+ const databaseQuery = databaseConnection . query ( query , parameters )
289
+ if ( onEnd ) databaseQuery . on ( "end" , onEnd )
290
+ if ( onError ) databaseQuery . on ( "error" , onError )
291
+ return databaseQuery . stream ( )
316
292
}
317
293
318
294
/**
0 commit comments