level-nulldel

Modify a level(up) datastore to treat a null "put" as a "del"

npm install level-nulldel
2 downloads in the last week
5 downloads in the last month

level-nulldel

See https://github.com/rvagg/node-levelup/issues/191.

WHAT

A small patch to a levelup database object, so that you can use a single put style interface for additions, modifications, and deletions.

HOW

var levelup = require('levelup');
var nulldel = require('level-nulldel');

var db = levelup('./mydb');

db.put('somekey', 'foo', function (err) {...});  // unaffected
db.put('somekey', null, function (err) {...});   // stores null as value

nulldel(db);  // monkey-patches this db object

db.put('somekey', 'bar', function (err) {...});  // unaffected, changes to bar
db.put('somekey', null, function (err) {...});   // deletes somekey

WHY

It unifies "change" requests, just as access requests all use get. This can simplify your code, and everything built on top of it.

Note that this prevents storing null as value with JSON encoding (undefined was already a no-no). For simple string encodings you can still use '' (the empty string) as value to represent emptiness.

WHO

This module was suggested by Rod Vagg, levelup's author, in a brief discussion on github, issue #191.

npm loves you