@@ -6,27 +6,32 @@ const opt = {
66} ;
77
88export function getLimitOffset ( query : string ) {
9- const decodedQuery = decodeURIComponent ( query ) ;
10- let ast = sqlParser . astify ( decodedQuery , opt ) ;
11- if ( Array . isArray ( ast ) && ast . length > 0 ) {
12- const astFirst = ast [ 0 ] ;
13- if ( astFirst ) {
14- ast = astFirst ;
9+ try {
10+ const decodedQuery = decodeURIComponent ( query ) ;
11+ let ast = sqlParser . astify ( decodedQuery , opt ) ;
12+ if ( Array . isArray ( ast ) && ast . length > 0 ) {
13+ const astFirst = ast [ 0 ] ;
14+ if ( astFirst ) {
15+ ast = astFirst ;
16+ }
1517 }
16- }
1718
18- let limit = null ;
19- let offset = null ;
19+ let limit = null ;
20+ let offset = null ;
2021
21- if ( "limit" in ast ) {
22- // If limit has a separator "offset", it contains both limit and offset values. Otherwise, only limit is set.
23- if ( ast . limit ?. seperator === "offset" ) {
24- limit = ast . limit ?. value ?. [ 0 ] ?. value ;
25- offset = ast . limit ?. value ?. [ 1 ] ?. value ;
26- } else {
27- limit = ast . limit ?. value ?. [ 0 ] ?. value ;
22+ if ( "limit" in ast ) {
23+ // If limit has a separator "offset", it contains both limit and offset values. Otherwise, only limit is set.
24+ if ( ast . limit ?. seperator === "offset" ) {
25+ limit = ast . limit ?. value ?. [ 0 ] ?. value ;
26+ offset = ast . limit ?. value ?. [ 1 ] ?. value ;
27+ } else {
28+ limit = ast . limit ?. value ?. [ 0 ] ?. value ;
29+ }
2830 }
29- }
3031
31- return { limit, offset } ;
32+ return { limit, offset } ;
33+ } catch ( error ) {
34+ console . error ( "Error parsing query:" , error ) ;
35+ return { limit : null , offset : null } ;
36+ }
3237}
0 commit comments