Permalink
Browse files

A few tweaks for limit/skip

  • Loading branch information...
1 parent c185031 commit 78dd440190a22ef04bf57a04b3ddd0cbb219c4ac mde committed Aug 20, 2012
Showing with 19 additions and 3 deletions.
  1. +10 −1 lib/adapters/sql/postgres.js
  2. +9 −2 lib/query/query.js
@@ -186,7 +186,10 @@ utils.mixin(Adapter.prototype, new (function () {
this.all = function (query, callback) {
var sql = ''
, conditions = this._serializeConditions(query.conditions)
- , sort = query.opts.sort;
+ , opts = query.opts
+ , sort = opts.sort
+ , limit = opts.limit
+ , skip = opts.skip;
sql += 'SELECT * FROM ' + this._tableizeModelName(query.model.modelName);
sql += ' ';
@@ -196,6 +199,12 @@ utils.mixin(Adapter.prototype, new (function () {
if (sort) {
sql += this._serializeSortOrder(sort);
}
+ if (skip) {
+ sql += ' OFFSET ' + skip;
+ }
+ if (limit) {
+ sql += ' LIMIT ' + limit;
+ }
sql += ';'
this.exec(sql, function (err, data) {
var res
View
@@ -15,7 +15,7 @@ query.Query.prototype = new (function () {
var _comparisonCtorNames = {
'eql': 'EqualTo'
- , 'ne': 'NotEqual'
+ , 'ne': 'NotEqualTo'
, 'in': 'In'
, 'like': 'Like'
, 'gt': 'GreaterThan'
@@ -197,8 +197,15 @@ query.Query.prototype = new (function () {
}
ret[prop] = parsed;
break;
+ case 'limit':
+ case 'skip':
+ if (isNaN(val)) {
+ throw new Error('"' + prop + '" must be a number.');
+ }
+ ret[prop] = Number(val);
+ break;
default:
- ret[prop] = opts[prop];
+ ret[prop] = val;
}
}
return ret;

0 comments on commit 78dd440

Please sign in to comment.