1+ var Utilities = require ( "./Utilities" ) ;
2+
13module . exports = AggregateFunctions ;
24
35function AggregateFunctions ( opts ) {
@@ -43,8 +45,8 @@ function AggregateFunctions(opts) {
4345 }
4446 return this ;
4547 } ,
46- order : function ( property , order ) {
47- opts . order = [ property , order ] ;
48+ order : function ( ) {
49+ opts . order = Utilities . standardizeOrder ( Array . prototype . slice . apply ( arguments ) ) ;
4850 return this ;
4951 } ,
5052 select : function ( ) {
@@ -79,9 +81,10 @@ function AggregateFunctions(opts) {
7981 }
8082
8183 var query = opts . driver . getQuery ( ) . select ( ) . from ( opts . table ) . select ( opts . properties ) ;
84+ var i , j ;
8285
83- for ( var i = 0 ; i < aggregates . length ; i ++ ) {
84- for ( var j = 0 ; j < aggregates [ i ] . length ; j ++ ) {
86+ for ( i = 0 ; i < aggregates . length ; i ++ ) {
87+ for ( j = 0 ; j < aggregates [ i ] . length ; j ++ ) {
8588 query [ aggregates [ i ] [ j ] . f ] ( aggregates [ i ] [ j ] . a , aggregates [ i ] [ j ] . alias ) ;
8689 }
8790 }
@@ -93,17 +96,21 @@ function AggregateFunctions(opts) {
9396 }
9497
9598 if ( opts . order ) {
96- query . order . apply ( query , opts . order ) ;
99+ for ( i = 0 ; i < opts . order . length ; i ++ ) {
100+ query . order ( opts . order [ i ] [ 0 ] , opts . order [ i ] [ 1 ] ) ;
101+ }
97102 }
98103 if ( opts . limit ) {
99104 query . offset ( opts . limit [ 0 ] ) . limit ( opts . limit [ 1 ] ) ;
100105 }
101106
107+ query = query . build ( ) ;
108+
102109 if ( opts . driver . opts && opts . driver . opts . debug ) {
103- require ( "./Debug" ) . sql ( opts . driver_name , query . build ( ) ) ;
110+ require ( "./Debug" ) . sql ( opts . driver_name , query ) ;
104111 }
105112
106- opts . driver . execQuery ( query . build ( ) , function ( err , data ) {
113+ opts . driver . execQuery ( query , function ( err , data ) {
107114 if ( err ) {
108115 return cb ( err ) ;
109116 }
0 commit comments