Allow empty array or value of `order`

This commit is contained in:
Raymond Feng 2018-08-07 15:36:24 -07:00
parent fa7a4b2d66
commit 1b1dc898fd
2 changed files with 13 additions and 0 deletions

View File

@ -1216,6 +1216,9 @@ SQLConnector.prototype.buildOrderBy = function(model, order) {
clauses.push(self.columnEscaped(model, t[0]) + ' ' + t[1]); clauses.push(self.columnEscaped(model, t[0]) + ' ' + t[1]);
} }
} }
if (!clauses.length) {
return '';
}
return 'ORDER BY ' + clauses.join(','); return 'ORDER BY ' + clauses.join(',');
}; };

View File

@ -270,6 +270,16 @@ describe('sql connector', function() {
expect(orderBy).to.eql('ORDER BY `NAME` ASC,`VIP` DESC'); expect(orderBy).to.eql('ORDER BY `NAME` ASC,`VIP` DESC');
}); });
it('builds order by with empty array', function() {
const orderBy = connector.buildOrderBy('customer', []);
expect(orderBy).to.eql('');
});
it('builds order by with empty string', function() {
const orderBy = connector.buildOrderBy('customer', '');
expect(orderBy).to.eql('');
});
it('builds fields for columns', function() { it('builds fields for columns', function() {
const fields = connector.buildFields('customer', const fields = connector.buildFields('customer',
{name: 'John', vip: true, unknown: 'Random'}); {name: 'John', vip: true, unknown: 'Random'});