Skip to content

Commit

Permalink
Adds more aggregate functions to the several drivers
Browse files Browse the repository at this point in the history
Supports alias to be able to have similar functions with the same name
across drivers
  • Loading branch information
dresende committed Apr 3, 2013
1 parent 0cd38eb commit d7d610b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/AggregateFunctions.js
Expand Up @@ -65,8 +65,16 @@ function AggregateFunctions(opts) {
};

for (var i = 0; i < opts.driver.aggregate_functions.length; i++) {
proto[opts.driver.aggregate_functions[i].toLowerCase()] = appendFunction(opts.driver.aggregate_functions[i].toLowerCase());
addAggregate(proto, opts.driver.aggregate_functions[i], appendFunction);
}

return proto;
}

function addAggregate(proto, fun, builder) {
if (Array.isArray(fun)) {
proto[fun[0].toLowerCase()] = builder((fun[1] || fun[0]).toLowerCase());
} else {
proto[fun.toLowerCase()] = builder(fun.toLowerCase());
}
}
3 changes: 3 additions & 0 deletions lib/Drivers/DML/mysql.js
Expand Up @@ -20,6 +20,9 @@ function Driver(config, connection, opts) {

this.aggregate_functions = [ "ABS", "CEIL", "FLOOR", "ROUND",
"AVG", "MIN", "MAX",
"LOG", "LOG2", "LOG10", "EXP", "POWER",
"ACOS", "ASIN", "ATAN", "COS", "SIN", "TAN",
"CONV", [ "RANDOM", "RAND" ], "RADIANS", "DEGREES",
"SUM", "COUNT" ];
}

Expand Down
3 changes: 3 additions & 0 deletions lib/Drivers/DML/postgres.js
Expand Up @@ -19,6 +19,9 @@ function Driver(config, connection, opts) {

this.aggregate_functions = [ "ABS", "CEIL", "FLOOR", "ROUND",
"AVG", "MIN", "MAX",
"LOG", "EXP", "POWER",
"ACOS", "ASIN", "ATAN", "COS", "SIN", "TAN",
"RANDOM", "RADIANS", "DEGREES",
"SUM", "COUNT" ];
}

Expand Down
3 changes: 3 additions & 0 deletions lib/Drivers/DML/postgresaxomic.js
Expand Up @@ -13,6 +13,9 @@ function Driver(config, connection, opts) {

this.aggregate_functions = [ "ABS", "CEIL", "FLOOR", "ROUND",
"AVG", "MIN", "MAX",
"LOG", "EXP", "POWER",
"ACOS", "ASIN", "ATAN", "COS", "SIN", "TAN",
"RANDOM", "RADIANS", "DEGREES",
"SUM", "COUNT" ];
}
Driver.prototype.sync = function (opts, cb) {
Expand Down
1 change: 1 addition & 0 deletions lib/Drivers/DML/sqlite.js
Expand Up @@ -19,6 +19,7 @@ function Driver(config, connection, opts) {

this.aggregate_functions = [ "ABS", "ROUND",
"AVG", "MIN", "MAX",
"RANDOM",
"SUM", "COUNT" ];
}

Expand Down

0 comments on commit d7d610b

Please sign in to comment.