Add tests for count & groupBy, and fix groupBy

This commit is contained in:
Jason LeBrun 2013-05-15 14:57:00 -07:00
parent c60774fda4
commit 90f7276464
3 changed files with 66 additions and 2 deletions

View File

@ -679,7 +679,7 @@
// Adds a `group by` clause to the query.
groupBy: function() {
this.groups = this.groups.concat(_.toArray(arguments));
this.groups = (this.groups||[]).concat(_.toArray(arguments));
return this;
},

View File

@ -9,4 +9,12 @@ module.exports = function(Knex, dbName, resolver) {
});
};
it('has a count', function(ok) {
Knex('accounts').count('id').then(resolver(ok), ok);
});
it("support the groupBy function", function(ok) {
Knex('accounts').count('id').groupBy('logins').then(resolver(ok), ok);
});
};

View File

@ -504,6 +504,34 @@ module.exports = {
bindings: []
}
},
'aggregate.2': {
mysql: {
sql: ['select count(`id`) as aggregate from `accounts`'],
bindings: []
},
postgres: {
sql: ['select count("id") as aggregate from "accounts"'],
bindings: []
},
sqlite3: {
sql: ['select count("id") as aggregate from "accounts"'],
bindings: []
}
},
'aggregate.3': {
mysql: {
sql: ['select count(`id`) as aggregate from `accounts` group by `logins`'],
bindings: []
},
postgres: {
sql: ['select count("id") as aggregate from "accounts" group by "logins"'],
bindings: []
},
sqlite3: {
sql: ['select count("id") as aggregate from "accounts" group by "logins"'],
bindings: []
}
},
'joins.1': {
mysql: {
sql: ['select `accounts`.*, `test_table_two`.`details` from `accounts` inner join `test_table_two` on `accounts`.`id` = `test_table_two`.`account_id`'],
@ -1961,6 +1989,34 @@ module.exports = {
aggregate: 10
}]
},
'aggregate.2': {
mysql: [{
aggregate: 6
}],
postgres: [{
aggregate: 6
}],
sqlite3: [{
aggregate: 6
}]
},
'aggregate.3': {
mysql: [{
aggregate: 2
}, {
aggregate: 4
}],
postgres: [{
aggregate: 2
}, {
aggregate: 4
}],
sqlite3: [{
aggregate: 2
}, {
aggregate: 4
}]
},
'joins.1': {
mysql: [{
id: 1,