11import { exprToSQL , getExprListSQL , orderOrPartitionByToSQL } from './expr'
22import { columnsToSQL } from './column'
3+ import { limitToSQL } from './limit'
34import { withToSql } from './with'
45import { tablesToSQL } from './tables'
56import { hasVal , commonOptionConnector , connector , topToSQL , toUpper } from './util'
@@ -21,20 +22,7 @@ import { hasVal, commonOptionConnector, connector, topToSQL, toUpper } from './u
2122
2223function selectToSQL ( stmt ) {
2324 const {
24- as_struct_val : asStructVal ,
25- columns,
26- distinct,
27- from,
28- for_sys_time_as_of : forSystem = { } ,
29- groupby,
30- having,
31- limit,
32- options,
33- orderby,
34- top,
35- window : windowInfo ,
36- with : withInfo ,
37- where,
25+ as_struct_val : asStructVal , columns, distinct, from, for_sys_time_as_of : forSystem = { } , groupby, having, limit, options, orderby, top, window : windowInfo , with : withInfo , where,
3826 } = stmt
3927 const clauses = [ withToSql ( withInfo ) , 'SELECT' , toUpper ( asStructVal ) ]
4028 clauses . push ( topToSQL ( top ) )
@@ -49,10 +37,7 @@ function selectToSQL(stmt) {
4937 clauses . push ( commonOptionConnector ( 'HAVING' , exprToSQL , having ) )
5038 clauses . push ( commonOptionConnector ( 'WINDOW' , exprToSQL , windowInfo ) )
5139 clauses . push ( orderOrPartitionByToSQL ( orderby , 'order by' ) )
52- if ( limit ) {
53- const { seperator, value } = limit
54- clauses . push ( connector ( 'LIMIT' , value . map ( exprToSQL ) . join ( `${ seperator === 'offset' ? ' ' : '' } ${ seperator . toUpperCase ( ) } ` ) ) )
55- }
40+ clauses . push ( limitToSQL ( limit ) )
5641 return clauses . filter ( hasVal ) . join ( ' ' )
5742}
5843
0 commit comments