Skip to content

Commit

Permalink
fix: order with empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
xwang1024 committed Mar 9, 2017
1 parent e8d8056 commit 964964c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ proto._orders = function (orders) {
}
}
}
return ' ORDER BY ' + values.join(', ');
return values.length ? ' ORDER BY ' + values.join(', ') : '';
};

proto._limit = function (limit, offset) {
Expand Down
19 changes: 19 additions & 0 deletions test/operator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,23 @@ describe('operator.test.js', function () {
}
});
});

describe('_orders()', function () {
it('should get order sql', function* () {
let op = new Operator();
assert.equal(op._orders(), '');
assert.equal(op._orders([]), '');
assert.equal(op._orders([null]), '');
assert.equal(op._orders([function() {}]), '');
assert.equal(op._orders(['id']), ' ORDER BY `id`');
assert.equal(op._orders(['test.id']), ' ORDER BY `test`.`id`');
assert.equal(op._orders(['id', 'name']), ' ORDER BY `id`, `name`');
assert.equal(op._orders(['id', null]), ' ORDER BY `id`');
assert.equal(op._orders(['id', ['name', 'desc']]), ' ORDER BY `id`, `name` DESC');
assert.equal(op._orders(['id', ['name', 'ASC']]), ' ORDER BY `id`, `name` ASC');
assert.equal(op._orders(['id', ['name', 'other']]), ' ORDER BY `id`, `name`');
assert.equal(op._orders([['id', 'asc'], ['name', 'desc']]), ' ORDER BY `id` ASC, `name` DESC');
assert.equal(op._orders([['id', 'asc'], ['name'], 'type']), ' ORDER BY `id` ASC, `name`, `type`');
});
});
});

0 comments on commit 964964c

Please sign in to comment.