🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

level-modify

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

level-modify

Modify an existing key in a levelup store.

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

level-modify

npm

Modify an existing key in a levelup store. Uses level-lock to prevent race conditions. See also: level-create, level-move

let db = require('level')('colors.db')
let modify = require('level-modify');

function redToBlue(color) {
	if (color === 'red') color = 'blue';
	return color;
}

db.put('fence', 'red', (err) => {
	modify(db, 'fence', redToBlue, (err) => {
		if (err && err.code === 'LOCKED') return console.error('conflict');
		db.get('fence', (err, color) => {
			console.log(color); // blue
		});
	});
});

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

Keywords

leveldb

FAQs

Package last updated on 07 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts