Pre/Post hooks for leveldb
Intercept put/delete/batch operations on levelup.
Warning - Breaking Changes
The API for implementing pre hooks has changed.
Instead of mutating an array at once, the prehook
is called on each change hook(change, add)
and may call add(_change)
to add a new item into the batch.
Examlpe
var levelup = require('levelup')
var timestamp = require('monotonic-timestamp')
var hooks = require('level-hooks')
levelup(file, {createIfMissing: true}, function (err, db) {
hooks()(db)
db.hooks.pre(function (change, add) {
if(!/~log-/.test(e.key.toString())
add({type: 'put', key: '~log-'+timestamp()+'-'+e.type, value: e.key})
})
db.hooks.post(function (err, ch) {
console.log(ch)
})
})
Used by map-reduce
to make map-reduce durable across crashes!