knex/test/integration/builder/aggregate.js
Nikhil Benesch 0bf4044b74 Add 'avg' aggregate function
The 'AVG' aggregate function is specified in the SQL standard and
supported by MySQL, PostgreSQL, and SQLite. Include tests, too.
2014-01-19 15:38:59 -05:00

42 lines
762 B
JavaScript

module.exports = function(knex) {
describe('Aggregate', function() {
it('has a sum', function() {
return knex('accounts').logMe().sum('logins');
});
it('has an avg', function() {
return knex('accounts').logMe().avg('logins');
});
it('has a count', function() {
return knex('accounts').logMe().count('id');
});
it('supports multiple aggregate functions', function() {
return knex('accounts').logMe().count('id').max('logins').min('logins');
});
it("support the groupBy function", function() {
return knex('accounts').logMe().count('id').groupBy('logins').then(function() {
return knex('accounts').logMe().count('id').groupBy('first_name');
});
});
});
};