Created function to remove an index

pull/2/head
Louis Chatriot 11 years ago
parent 8c8cc8fea4
commit 0a1d4cac78
  1. 17
      lib/datastore.js
  2. 2
      lib/model.js
  3. 4
      test/db.test.js
  4. 5
      test/model.test.js

@ -118,6 +118,23 @@ Datastore.prototype.ensureIndex = function (options, cb) {
};
/**
* Remove an index
* @param {String} fieldName
* @param {Function} cb Optional callback, signature: err
*/
Datastore.prototype.removeIndex = function (fieldName, cb) {
var callback = cb || function () {};
delete this.indexes[fieldName];
this.persistence.persistNewState([{ $$indexRemoved: fieldName }], function (err) {
if (err) { return callback(err); }
return callback(null);
});
};
/**
* Add one or several document(s) to all indexes
*/

@ -26,7 +26,7 @@ var dateToJSON = function () { return { $$date: this.getTime() }; }
* But you really need to want it to trigger such behaviour, even when warned not to use '$' at the beginning of the field names...
*/
function checkKey (k, v) {
if (k[0] === '$' && !(k === '$$date' && typeof v === 'number') && !(k === '$$deleted' && v === true) && !(k === '$$indexCreated')) {
if (k[0] === '$' && !(k === '$$date' && typeof v === 'number') && !(k === '$$deleted' && v === true) && !(k === '$$indexCreated') && !(k === '$$indexRemoved')) {
throw 'Field names cannot begin with the $ character';
}

@ -2131,9 +2131,9 @@ describe('Database', function () {
db.indexes.planet.getAll().length.should.equal(3);
db.indexes.bloup.getAll().length.should.equal(0);
db.indexes.planet.unique.should.equal(true);
db.indexes.planet.sparse.should.equal(false);
db.indexes.planet.sparse.should.equal(false);
db.indexes.bloup.unique.should.equal(false);
db.indexes.bloup.sparse.should.equal(true);
db.indexes.bloup.sparse.should.equal(true);
done();
});

@ -112,12 +112,13 @@ describe('Model', function () {
c.test[2].again.should.equal('yes');
});
it('Reject field names beginning with a $ sign or containing a dot, except the three edge cases', function () {
it('Reject field names beginning with a $ sign or containing a dot, except the four edge cases', function () {
var a1 = { $something: 'totest' }
, a2 = { "with.dot": 'totest' }
, e1 = { $$date: 4321 }
, e2 = { $$deleted: true }
, e3 = { $$indexCreated: "indexName" }
, e4 = { $$indexRemoved: "indexName" }
, b;
// Normal cases
@ -127,6 +128,8 @@ describe('Model', function () {
// Edge cases
b = model.serialize(e1);
b = model.serialize(e2);
b = model.serialize(e3);
b = model.serialize(e4);
});
it('Can serialize string fields with a new line without breaking the DB', function (done) {

Loading…
Cancel
Save