@@ -63,49 +63,49 @@ function ResourcesGetter(model, options, params) {
63
63
}
64
64
65
65
async function getWhere ( ) {
66
- return new P ( async ( resolve , reject ) => {
67
- const where = { } ;
68
- where [ OPERATORS . AND ] = [ ] ;
66
+ const where = { } ;
67
+ where [ OPERATORS . AND ] = [ ] ;
69
68
70
- if ( params . search ) {
71
- where [ OPERATORS . AND ] . push ( getSearchBuilder ( ) . perform ( ) ) ;
72
- }
69
+ if ( params . search ) {
70
+ where [ OPERATORS . AND ] . push ( getSearchBuilder ( ) . perform ( ) ) ;
71
+ }
73
72
74
- if ( params . filters ) {
75
- where [ OPERATORS . AND ] . push ( await handleFilterParams ( ) ) ;
76
- }
73
+ if ( params . filters ) {
74
+ where [ OPERATORS . AND ] . push ( await handleFilterParams ( ) ) ;
75
+ }
77
76
78
- if ( segmentWhere ) {
79
- where [ OPERATORS . AND ] . push ( segmentWhere ) ;
80
- }
77
+ if ( segmentWhere ) {
78
+ where [ OPERATORS . AND ] . push ( segmentWhere ) ;
79
+ }
81
80
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 ( ) ;
85
83
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 ]
89
90
. query ( queryToFilterRecords , {
90
91
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 ) ) ;
103
92
} ) ;
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 ) ;
104
104
}
105
- return resolve ( where ) ;
106
- } ) ;
107
- }
105
+ }
108
106
107
+ return where ;
108
+ }
109
109
110
110
async function getRecords ( ) {
111
111
fieldNamesRequested = fieldNamesRequested || await getFieldNamesRequested ( ) ;
0 commit comments