Modify a level(up) datastore to treat a null "put" as a "del"
A small patch to a levelup database object, so that you can use a single
put style interface for additions, modifications, and deletions.
var levelup = require'levelup';var nulldel = require'level-nulldel';var db = levelup'./mydb';dbput'somekey' 'foo' ; // unaffecteddbput'somekey' null ; // stores null as valuenulldeldb; // monkey-patches this db objectdbput'somekey' 'bar' ; // unaffected, changes to bardbput'somekey' null ; // deletes somekey
It unifies "change" requests, just as access requests all use
This can simplify your code, and everything built on top of it.
Note that this prevents storing
null as value with JSON encoding (
was already a no-no). For simple string encodings you can still use
empty string) as value to represent emptiness.
This module was suggested by Rod Vagg, levelup's author, in a brief discussion on github, issue #191.