mirror of
https://github.com/knex/knex.git
synced 2025-12-26 14:38:38 +00:00
Drop default output name for aggregate functions.
This commit is contained in:
parent
64f9deb651
commit
35047912fe
@ -75,7 +75,7 @@ define(function(require, exports) {
|
||||
if (qb.flags.distinct && column !== '*') {
|
||||
column = 'distinct ' + column;
|
||||
}
|
||||
return 'select ' + qb.aggregate.type + '(' + column + ') as aggregate';
|
||||
return 'select ' + qb.aggregate.type + '(' + column + ')';
|
||||
},
|
||||
|
||||
// Compiles the columns in the query, specifying if an item was distinct.
|
||||
@ -350,4 +350,4 @@ define(function(require, exports) {
|
||||
|
||||
})(
|
||||
typeof define === 'function' && define.amd ? define : function (factory) { factory(require, exports, module); }
|
||||
);
|
||||
);
|
||||
|
||||
@ -2,82 +2,82 @@ module.exports = {
|
||||
'has a sum': {
|
||||
mysql: {
|
||||
bindings: [],
|
||||
sql: 'select sum(`logins`) as aggregate from `accounts`',
|
||||
sql: 'select sum(`logins`) from `accounts`',
|
||||
result: [{
|
||||
aggregate: 10
|
||||
'sum(`logins`)': 10
|
||||
}]
|
||||
},
|
||||
postgresql: {
|
||||
bindings: [],
|
||||
sql: 'select sum("logins") as aggregate from "accounts"',
|
||||
sql: 'select sum("logins") from "accounts"',
|
||||
result: [{
|
||||
aggregate: '10'
|
||||
'sum': '10'
|
||||
}]
|
||||
},
|
||||
sqlite3: {
|
||||
bindings: [],
|
||||
sql: 'select sum("logins") as aggregate from "accounts"',
|
||||
sql: 'select sum("logins") from "accounts"',
|
||||
result: [{
|
||||
aggregate: 10
|
||||
'sum("logins")': 10
|
||||
}]
|
||||
}
|
||||
},
|
||||
'has a count': {
|
||||
mysql: {
|
||||
bindings: [],
|
||||
sql: 'select count(`id`) as aggregate from `accounts`',
|
||||
sql: 'select count(`id`) from `accounts`',
|
||||
result: [{
|
||||
aggregate: 6
|
||||
'count(`id`)': 6
|
||||
}]
|
||||
},
|
||||
postgresql: {
|
||||
bindings: [],
|
||||
sql: 'select count("id") as aggregate from "accounts"',
|
||||
sql: 'select count("id") from "accounts"',
|
||||
result: [{
|
||||
aggregate: '6'
|
||||
'count': '6'
|
||||
}]
|
||||
},
|
||||
sqlite3: {
|
||||
bindings: [],
|
||||
sql: 'select count("id") as aggregate from "accounts"',
|
||||
sql: 'select count("id") from "accounts"',
|
||||
result: [{
|
||||
aggregate: 6
|
||||
'count("id")': 6
|
||||
}]
|
||||
}
|
||||
},
|
||||
'support the groupBy function': {
|
||||
mysql: {
|
||||
bindings: [[],[]],
|
||||
sql: ['select count(`id`) as aggregate from `accounts` group by `logins`','select count(`id`) as aggregate from `accounts` group by `first_name`'],
|
||||
sql: ['select count(`id`) from `accounts` group by `logins`','select count(`id`) from `accounts` group by `first_name`'],
|
||||
result: [[{
|
||||
aggregate: 2
|
||||
'count(`id`)': 2
|
||||
},{
|
||||
aggregate: 4
|
||||
'count(`id`)': 4
|
||||
}],[{
|
||||
aggregate: 6
|
||||
'count(`id`)': 6
|
||||
}]]
|
||||
},
|
||||
postgresql: {
|
||||
bindings: [[],[]],
|
||||
sql: ['select count("id") as aggregate from "accounts" group by "logins"','select count("id") as aggregate from "accounts" group by "first_name"'],
|
||||
sql: ['select count("id") from "accounts" group by "logins"','select count("id") from "accounts" group by "first_name"'],
|
||||
result: [[{
|
||||
aggregate: '2'
|
||||
'count': '2'
|
||||
},{
|
||||
aggregate: '4'
|
||||
'count': '4'
|
||||
}],[{
|
||||
aggregate: '6'
|
||||
'count': '6'
|
||||
}]]
|
||||
},
|
||||
sqlite3: {
|
||||
bindings: [[],[]],
|
||||
sql: ['select count("id") as aggregate from "accounts" group by "logins"','select count("id") as aggregate from "accounts" group by "first_name"'],
|
||||
sql: ['select count("id") from "accounts" group by "logins"','select count("id") from "accounts" group by "first_name"'],
|
||||
result: [[{
|
||||
aggregate: 2
|
||||
'count("id")': 2
|
||||
},{
|
||||
aggregate: 4
|
||||
'count("id")': 4
|
||||
}],[{
|
||||
aggregate: 6
|
||||
'count("id")': 6
|
||||
}]]
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@ -115,7 +115,7 @@ describe('Builder', function () {
|
||||
|
||||
it('should call toString correctly on count()', function() {
|
||||
|
||||
var output = "select count(`id`) as aggregate from `users`";
|
||||
var output = "select count(`id`) from `users`";
|
||||
|
||||
expect(builder.from('users').count('id').toString()).to.equal(output);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user