Can remove an index

pull/2/head
Louis Chatriot 11 years ago
parent 0a1d4cac78
commit 03f68398e6
  1. 2
      lib/persistence.js
  2. 24
      test/db.test.js

@ -217,6 +217,8 @@ Persistence.treatRawData = function (rawData) {
} }
} else if (doc.$$indexCreated && doc.$$indexCreated.fieldName != undefined) { } else if (doc.$$indexCreated && doc.$$indexCreated.fieldName != undefined) {
indexes[doc.$$indexCreated.fieldName] = doc.$$indexCreated; indexes[doc.$$indexCreated.fieldName] = doc.$$indexCreated;
} else if (typeof doc.$$indexRemoved === "string") {
delete indexes[doc.$$indexRemoved];
} }
} catch (e) { } catch (e) {
} }

@ -1291,7 +1291,7 @@ describe('Database', function () {
describe('Using indexes', function () { describe('Using indexes', function () {
describe('ensureIndex and index initialization in database loading', function () { describe.only('ensureIndex and index initialization in database loading', function () {
it('ensureIndex can be called right after a loadDatabase and be initialized and filled correctly', function (done) { it('ensureIndex can be called right after a loadDatabase and be initialized and filled correctly', function (done) {
var now = new Date() var now = new Date()
@ -1524,8 +1524,26 @@ describe('Database', function () {
}); });
}); });
it('Can remove an index', function (done) {
d.ensureIndex({ fieldName: 'e' }, function (err) {
assert.isNull(err);
Object.keys(d.indexes).length.should.equal(2);
assert.isNotNull(d.indexes.e);
d.removeIndex("e", function (err) {
assert.isNull(err);
Object.keys(d.indexes).length.should.equal(1);
assert.isUndefined(d.indexes.e);
done();
});
});
});
}); // ==== End of 'ensureIndex and index initialization in database loading' ==== // }); // ==== End of 'ensureIndex and index initialization in database loading' ==== //
describe('Indexing newly inserted documents', function () { describe('Indexing newly inserted documents', function () {
it('Newly inserted documents are indexed', function (done) { it('Newly inserted documents are indexed', function (done) {
@ -2006,10 +2024,10 @@ describe('Database', function () {
}); });
}); });
}); // ==== End of 'Removing indexes upon document update' ==== // }); // ==== End of 'Updating indexes upon document remove' ==== //
describe.only('Persisting indexes', function () { describe.skip('Persisting indexes', function () {
it('Indexes are persisted to a separate file and recreated upon reload', function (done) { it('Indexes are persisted to a separate file and recreated upon reload', function (done) {
var persDb = "workspace/persistIndexes.db" var persDb = "workspace/persistIndexes.db"

Loading…
Cancel
Save