Why? If you're making a lot of changes dependent on the current value of a
key, you'll find the gap between a
get and a
put becomes important:
for var i = 0; i < 100; i += 1db
The above example will probably result in
a-key being set to 1 and staying
level-updater keeps track of overlapping calls like this and handles
them cleanly for you.
npm install level-updater
require('level-updater')(db, updater)(key, [param], [callback])
dbis the levelup instance to plug into.
updateris the method used to update each time a value is hit.
And for each call:
keyis the key to update.
paramis an optional parameter for passing to
callbackis called after the new value has been stored in the database.
Take this example for incrementing numbers:
var db = __dirname + '/db'var update =var counter = 0dbinc =for var i = 0; i < 200; i += 1db
And this for merging JSON objects:
var db = __dirname + '/db'var update =dbmerge =dbdb