Drop default output name for aggregate functions.

This commit is contained in:
Luigy Leon 2013-11-23 11:44:25 -05:00
parent 64f9deb651
commit 35047912fe
3 changed files with 28 additions and 28 deletions

View File

@ -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); }
);
);

View File

@ -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
}]]
}
}
};
};

View File

@ -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);