felixge/node-dirty

remove() removes the doc even if was set again

jviereck opened this issue · 4 comments

In some cases it can happen, that you remove a doc and add it later on again, for instance:


    db.set(ID, DOC);
    db.remove(ID);
    db.set(ID, DOC2);

    db.flush().addCallback(function() {
        sys.debug('flushed');
        sys.debug(JSON.stringify(db.get(ID))); // [1]
     });

In this case, the output in [1] is "undefined", because after flushing the db, the callback defined in the remove() function removes the doc, even if it was set again.

To get around this, the set() function should take care if the passed ID is in the _memoryID array and if this is true, then override the former as delete marked doc with the new doc passed in the set() function. When the db is flushed later, only the docs have to be removed, that are marked as deleted (doc._deleted == true).

I've implemented this here: http://gist.github.com/324631.

Julian

I'm working on a new version with a much simplified internal storage approach. For now I updated the Readme to indicate the current status of the project.

awesome :) Tell me if I can support you in any way.

Using dirty for any active projects, regardless the size, would be very nice.

I have a bunch of things I want to use it for, but until JSConf I'll mostly end up just developing it as an academic exercise : ). So any real-world feedback is very welcome.

Oh, and I'm planning to add a plugin system of some kind which I'd love to see people make us of to build things like indexing, map reduce, etc.

I just released dirty v0.9, a complete re-write. This issue should not longer exist.