Skip to content

Commit c9500b5

Browse files
committed
Add limit function to tables.
1 parent 40272b5 commit c9500b5

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

lib/table.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,10 @@ Table.prototype.indexes = function() {
297297
return new Query(this).indexes();
298298
};
299299

300+
Table.prototype.limit = function () {
301+
var query = new Query(this);
302+
query.limit.apply(query, arguments);
303+
return query;
304+
};
305+
300306
module.exports = Table;

test/table-tests.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,14 @@ test('dialects', function () {
235235
actual = foo.join(bar).on(bar.id.equals(1)).toString();
236236
assert.equal(actual, '"foo" INNER JOIN "bar" ON ("bar"."id" = 1)');
237237
});
238+
239+
test('limit', function () {
240+
var user = Table.define({
241+
name: 'user',
242+
columns: ['id', 'name']
243+
});
244+
var query = user.limit(3);
245+
assert.equal(query.nodes.length, 1);
246+
assert.equal(query.nodes[0].type, 'LIMIT');
247+
assert.equal(query.nodes[0].count, 3);
248+
});

0 commit comments

Comments
 (0)