@@ -57,15 +57,11 @@ async function beforeQuery(opts: {
5757} ) : Promise < { sql : string ; params ?: unknown [ ] } > {
5858 let { sql, params, dataSource, config } = opts
5959
60- if ( dataSource ?. plugins ?. length ) {
61- await Promise . all (
62- dataSource . plugins . map ( async ( plugin : StarbasePlugin ) => {
63- const { sql : _sql , params : _params } =
64- await plugin . beforeQuery ( opts )
65- sql = _sql
66- params = _params
67- } )
68- )
60+ if ( dataSource ?. registry ) {
61+ const { sql : _sql , params : _params } =
62+ await dataSource ?. registry ?. beforeQuery ( opts )
63+ sql = _sql
64+ params = _params
6965 }
7066
7167 return { sql, params }
@@ -81,13 +77,10 @@ async function afterQuery(opts: {
8177 let { result, isRaw, dataSource } = opts
8278 result = isRaw ? transformRawResults ( result , 'from' ) : result
8379
84- if ( dataSource ?. plugins ?. length ) {
85- await Promise . all (
86- dataSource . plugins . map ( async ( plugin : StarbasePlugin ) => {
87- result = await plugin . afterQuery ( opts )
88- } )
89- )
90- }
80+ result = await dataSource ?. registry ?. afterQuery ( {
81+ ...opts ,
82+ result,
83+ } )
9184
9285 return isRaw ? transformRawResults ( result , 'to' ) : result
9386}
@@ -100,7 +93,7 @@ function transformRawResults(
10093 // Convert our result from the `raw` output to a traditional object
10194 result = {
10295 ...result ,
103- rows : result . rows . map ( ( row : any ) =>
96+ rows : result ? .rows ? .map ( ( row : any ) =>
10497 result . columns . reduce (
10598 ( obj : any , column : string , index : number ) => {
10699 obj [ column ] = row [ index ]
0 commit comments