mirror of
https://github.com/knex/knex.git
synced 2025-09-23 15:14:19 +00:00
Add tests for count & groupBy, and fix groupBy
This commit is contained in:
parent
c60774fda4
commit
90f7276464
2
knex.js
2
knex.js
@ -679,7 +679,7 @@
|
|||||||
|
|
||||||
// Adds a `group by` clause to the query.
|
// Adds a `group by` clause to the query.
|
||||||
groupBy: function() {
|
groupBy: function() {
|
||||||
this.groups = this.groups.concat(_.toArray(arguments));
|
this.groups = (this.groups||[]).concat(_.toArray(arguments));
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
@ -504,6 +504,34 @@ module.exports = {
|
|||||||
bindings: []
|
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': {
|
'joins.1': {
|
||||||
mysql: {
|
mysql: {
|
||||||
sql: ['select `accounts`.*, `test_table_two`.`details` from `accounts` inner join `test_table_two` on `accounts`.`id` = `test_table_two`.`account_id`'],
|
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: 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': {
|
'joins.1': {
|
||||||
mysql: [{
|
mysql: [{
|
||||||
id: 1,
|
id: 1,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user