level-modify
Modify an existing key in a levelup store. Uses level-lock to prevent race conditions. See also: level-create, level-move
let db = 'colors.db'let modify = ; { if color === 'red' color = 'blue'; return color;} db;
Methods
let modify = require('level-modify');
modify(db, key, mod, callback));
Modify the value at key
. mod
can be a function in the form of function(oldValue) {return newValue;}
or an object which will be merged with the old value like so: Object.assign(oldValue, mod);
If the key is write-locked by a concurrent operation an error will be given to the callback with err.code
being 'LOCKED'
. Like other levelup methods if callback is omitted errors will be thrown.
Alternatively install onto the db object:
require('level-modify').install(db);
db.modify(key, mod, callback);
License
MIT