Returning cursor conflicts with the executor

pull/2/head
Louis Chatriot 11 years ago
parent 8a98ddacb8
commit b8f641e0fe
  1. 10
      lib/cursor.js
  2. 2
      lib/datastore.js
  3. 4
      test/cursor.test.js
  4. 19
      test/db.test.js

@ -46,9 +46,11 @@ Cursor.prototype.sort = function(sortQuery) {
/** /**
* Get all matching elements * Get all matching elements
* This is an internal function, use exec which uses the executor
*
* @param {Function} callback - Signature: err, results * @param {Function} callback - Signature: err, results
*/ */
Cursor.prototype.exec = function(callback) { Cursor.prototype.exec = function(callback) {
var candidates = this.db.getCandidates(this.query) var candidates = this.db.getCandidates(this.query)
, res = [], added = 0, skipped = 0, self = this , res = [], added = 0, skipped = 0, self = this
, i , i
@ -93,6 +95,12 @@ Cursor.prototype.sort = function(sortQuery) {
return callback(null, res); return callback(null, res);
}; };
// Cursor.prototype.exec = function () {
// console.log("=============IN EXEC");
// this.db.executor.push({ this: this, fn: this._exec, arguments: arguments });
// };
// Interface // Interface
module.exports = Cursor; module.exports = Cursor;

@ -462,8 +462,6 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) {
if (doc) { if (doc) {
return cb(); return cb();
} else { } else {
// The upserted document is the query (since for now queries have the same structure as
// documents), modified by the updateQuery
return self._insert(model.modify(query, updateQuery), function (err) { return self._insert(model.modify(query, updateQuery), function (err) {
if (err) { return callback(err); } if (err) { return callback(err); }
return callback(null, 1, true); return callback(null, 1, true);

@ -531,6 +531,10 @@ describe('Cursor', function () {
} }
], done); ], done);
}); });
it.skip('Multiple consecutive sorts', function(done) {
done();
});
}); // ===== End of 'Sorting' ===== }); // ===== End of 'Sorting' =====

@ -602,6 +602,25 @@ describe('Database', function () {
}); });
}); });
}); });
it.only('Can use sort, skip and limit if the callback is not passed to find but to exec', function (done) {
d.insert({ a: 2, hello: 'world' }, function () {
d.insert({ a: 24, hello: 'earth' }, function () {
d.insert({ a: 13, hello: 'blueplanet' }, function () {
d.insert({ a: 15, hello: 'home' }, function () {
d.find({}).sort({ a: 1 }).limit(2).exec(function (err, docs) {
assert.isNull(err);
docs.length.should.equal(2);
docs[0].hello.should.equal('world');
docs[1].hello.should.equal('blueplanet');
done();
});
});
});
});
});
});
}); // ==== End of 'Find' ==== // }); // ==== End of 'Find' ==== //

Loading…
Cancel
Save