Ready to roll out new architecture

pull/2/head
Louis Chatriot 12 years ago
parent 14b4c245bf
commit 1b7366abd3
  1. 8
      lib/datastore.js
  2. 32
      test/db.test.js

@ -419,7 +419,7 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) {
});
}
, function () { // Perform the update
var modified;
var modifiedDoc;
candidates = self.getCandidates(query);
@ -427,9 +427,9 @@ Datastore.prototype._update = function (query, updateQuery, options, cb) {
for (i = 0; i < candidates.length; i += 1) {
if (model.match(candidates[i], query) && (multi || numReplaced === 0)) {
numReplaced += 1;
modified = model.modify(candidates[i], updateQuery);
self.updateIndexes(candidates[i], modified);
candidates[i] = modified;
modifiedDoc = model.modify(candidates[i], updateQuery);
self.updateIndexes(candidates[i], modifiedDoc);
candidates[i] = modifiedDoc;
updatedDocs.push(candidates[i]);
}
}

@ -1109,7 +1109,7 @@ describe('Database', function () {
}); // ==== End of 'Remove' ==== //
describe.only('Using indexes', function () {
describe.skip('Using indexes', function () {
describe('ensureIndex and index initialization in database loading', function () {
@ -1451,7 +1451,31 @@ describe('Database', function () {
describe('Updating indexes upon document update', function () {
it.skip('Indexes get updated when a document (or multiple documents) is updated', function (done) {
it('Updating docs still works as before with an index', function (done) {
d.ensureIndex({ fieldName: 'a' });
d.insert({ a: 1, b: 'hello' }, function (err, doc1) {
d.insert({ a: 2, b: 'si' }, function (err, doc2) {
d.update({ a: 1 }, { $set: { a: 456, b: 'no' } }, {}, function (err, nr) {
assert.isNull(err);
nr.should.equal(1);
//console.log(d.data);
return done();
d.update({}, { $inc: { a: 10 }, $set: { b: 'same' } }, { multi: true }, function () {
assert.isNull(err);
nr.should.equal(2);
done();
});
});
});
});
});
it('Indexes get updated when a document (or multiple documents) is updated', function (done) {
d.ensureIndex({ fieldName: 'a' });
d.ensureIndex({ fieldName: 'b' });
@ -1460,8 +1484,6 @@ describe('Database', function () {
d.update({ a: 1 }, { $set: { a: 456, b: 'no' } }, {}, function (err, nr) {
assert.isNull(err);
nr.should.equal(1);
console.log(d.data);
throw 'fds'; // TODO
d.indexes.a.tree.getNumberOfKeys().should.equal(2);
d.indexes.a.getMatching(456)[0]._id.should.equal(doc1._id);
@ -1471,8 +1493,6 @@ describe('Database', function () {
d.indexes.b.getMatching('no')[0]._id.should.equal(doc1._id);
d.indexes.b.getMatching('si')[0]._id.should.equal(doc2._id);
console.log("========================");
console.log("========================");
d.update({}, { $inc: { a: 10 }, $set: { b: 'same' } }, { multi: true }, function () {
assert.isNull(err);
nr.should.equal(2);

Loading…
Cancel
Save