1
+ var Utilities = require ( "./Utilities" ) ;
2
+
1
3
module . exports = AggregateFunctions ;
2
4
3
5
function AggregateFunctions ( opts ) {
@@ -43,8 +45,8 @@ function AggregateFunctions(opts) {
43
45
}
44
46
return this ;
45
47
} ,
46
- order : function ( property , order ) {
47
- opts . order = [ property , order ] ;
48
+ order : function ( ) {
49
+ opts . order = Utilities . standardizeOrder ( Array . prototype . slice . apply ( arguments ) ) ;
48
50
return this ;
49
51
} ,
50
52
select : function ( ) {
@@ -79,9 +81,10 @@ function AggregateFunctions(opts) {
79
81
}
80
82
81
83
var query = opts . driver . getQuery ( ) . select ( ) . from ( opts . table ) . select ( opts . properties ) ;
84
+ var i , j ;
82
85
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 ++ ) {
85
88
query [ aggregates [ i ] [ j ] . f ] ( aggregates [ i ] [ j ] . a , aggregates [ i ] [ j ] . alias ) ;
86
89
}
87
90
}
@@ -93,17 +96,21 @@ function AggregateFunctions(opts) {
93
96
}
94
97
95
98
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
+ }
97
102
}
98
103
if ( opts . limit ) {
99
104
query . offset ( opts . limit [ 0 ] ) . limit ( opts . limit [ 1 ] ) ;
100
105
}
101
106
107
+ query = query . build ( ) ;
108
+
102
109
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 ) ;
104
111
}
105
112
106
- opts . driver . execQuery ( query . build ( ) , function ( err , data ) {
113
+ opts . driver . execQuery ( query , function ( err , data ) {
107
114
if ( err ) {
108
115
return cb ( err ) ;
109
116
}
0 commit comments