@@ -6,22 +6,25 @@ var util = require('util');
66var templateChecks = require ( '../../utils/templateChecks' ) ;
77
88var Dialect = module . exports = function ( builder ) {
9+ builder . options . valuesPrefix = '@' ;
910 BaseDialect . call ( this , builder ) ;
1011
11- this . blocks . set ( 'limit' , function ( params ) {
12+ this . blocks . set ( 'limit' , function ( params ) {
1213 return ( params . offset ) ? '' : 'TOP(' + builder . _pushValue ( params . limit ) + ')' ;
1314 } ) ;
1415
15- this . blocks . set ( 'offset' , function ( params ) {
16- var pre = ( ! params . sort ) ? 'ORDER BY 1 ' : '' ;
17- if ( params . limit ) {
18- return pre + 'OFFSET ' + params . offset + ' ROWS FETCH NEXT ' + params . limit + ' ROWS ONLY' ;
19- } else {
20- return pre + 'OFFSET ' + params . offset + ' ROWS' ;
21- }
16+ this . blocks . set ( 'offset' , function ( params ) {
17+ var pre = ( ! params . sort ) ? 'ORDER BY 1 ' : '' ;
18+ if ( params . limit ) {
19+ var str = pre + 'OFFSET ' + builder . _pushValue ( params . offset ) ;
20+ str += ' ROWS FETCH NEXT ' + builder . _pushValue ( params . limit ) + ' ROWS ONLY' ;
21+ return str ;
22+ } else {
23+ return pre + 'OFFSET ' + builder . _pushValue ( params . offset ) + ' ROWS' ;
24+ }
2225 } ) ;
2326
24- this . templates . set ( 'select' , {
27+ this . templates . set ( 'select' , {
2528 pattern : '{with} {withRecursive} select {limit} {distinct} {fields} ' +
2629 'from {from} {table} {query} {select} {expression} {alias} ' +
2730 '{join} {condition} {group} {having} {sort} {offset}' ,
@@ -58,7 +61,7 @@ var Dialect = module.exports = function(builder) {
5861
5962 templateChecks . propType ( type , params , 'sort' , [ 'string' , 'array' , 'object' ] ) ;
6063
61- templateChecks . propType ( type , params , 'offset' , [ 'number' , 'string' ] ) ;
64+ templateChecks . propType ( type , params , 'offset' , [ 'number' , 'string' ] ) ;
6265 templateChecks . propType ( type , params , 'limit' , [ 'number' , 'string' ] ) ;
6366 }
6467 } ) ;
0 commit comments