@@ -63,49 +63,49 @@ function ResourcesGetter(model, options, params) {
6363 }
6464
6565 async function getWhere ( ) {
66- return new P ( async ( resolve , reject ) => {
67- const where = { } ;
68- where [ OPERATORS . AND ] = [ ] ;
66+ const where = { } ;
67+ where [ OPERATORS . AND ] = [ ] ;
6968
70- if ( params . search ) {
71- where [ OPERATORS . AND ] . push ( getSearchBuilder ( ) . perform ( ) ) ;
72- }
69+ if ( params . search ) {
70+ where [ OPERATORS . AND ] . push ( getSearchBuilder ( ) . perform ( ) ) ;
71+ }
7372
74- if ( params . filters ) {
75- where [ OPERATORS . AND ] . push ( await handleFilterParams ( ) ) ;
76- }
73+ if ( params . filters ) {
74+ where [ OPERATORS . AND ] . push ( await handleFilterParams ( ) ) ;
75+ }
7776
78- if ( segmentWhere ) {
79- where [ OPERATORS . AND ] . push ( segmentWhere ) ;
80- }
77+ if ( segmentWhere ) {
78+ where [ OPERATORS . AND ] . push ( segmentWhere ) ;
79+ }
8180
82- if ( params . segmentQuery ) {
83- const queryToFilterRecords = params . segmentQuery . trim ( ) ;
84- new LiveQueryChecker ( ) . perform ( queryToFilterRecords ) ;
81+ if ( params . segmentQuery ) {
82+ const queryToFilterRecords = params . segmentQuery . trim ( ) ;
8583
86- // WARNING: Choosing the first connection might generate issues if the model does not
87- // belongs to this database.
88- return options . connections [ 0 ]
84+ new LiveQueryChecker ( ) . perform ( queryToFilterRecords ) ;
85+
86+ // WARNING: Choosing the first connection might generate issues if the model does not
87+ // belongs to this database.
88+ try {
89+ const results = await options . connections [ 0 ]
8990 . query ( queryToFilterRecords , {
9091 type : options . sequelize . QueryTypes . SELECT ,
91- } )
92- . then ( ( results ) => {
93- const recordIds = results . map ( ( result ) => result [ primaryKey ] || result . id ) ;
94- const condition = { [ primaryKey ] : { } } ;
95- condition [ primaryKey ] [ OPERATORS . IN ] = recordIds ;
96- where [ OPERATORS . AND ] . push ( condition ) ;
97-
98- return resolve ( where ) ;
99- } , ( error ) => {
100- const errorMessage = `Invalid SQL query for this Live Query segment:\n${ error . message } ` ;
101- logger . error ( errorMessage ) ;
102- reject ( new ErrorHTTP422 ( errorMessage ) ) ;
10392 } ) ;
93+
94+ const recordIds = results . map ( ( result ) => result [ primaryKey ] || result . id ) ;
95+ const condition = { [ primaryKey ] : { } } ;
96+ condition [ primaryKey ] [ OPERATORS . IN ] = recordIds ;
97+ where [ OPERATORS . AND ] . push ( condition ) ;
98+
99+ return where ;
100+ } catch ( error ) {
101+ const errorMessage = `Invalid SQL query for this Live Query segment:\n${ error . message } ` ;
102+ logger . error ( errorMessage ) ;
103+ throw new ErrorHTTP422 ( errorMessage ) ;
104104 }
105- return resolve ( where ) ;
106- } ) ;
107- }
105+ }
108106
107+ return where ;
108+ }
109109
110110 async function getRecords ( ) {
111111 fieldNamesRequested = fieldNamesRequested || await getFieldNamesRequested ( ) ;
0 commit comments