-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.js
37 lines (33 loc) · 919 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var hook = require('./')
var MemDB = require('memdb')
var sub = require('sublevel')
var db = hook(sub(MemDB(), 'test', { valueEncoding: 'json' }), { protectHook: true })
function prehook (operation, cb) {
console.log('this should run before the db operation')
console.log(operation)
cb()
}
function posthook (operation, cb) {
console.log('this should run after the db operation')
console.log(operation)
cb()
}
db.prehooks.push(prehook)
db.posthooks.push(posthook)
db.put('beep', 'boop', function (err) {
if (err) throw err
db.del('beep', function (err) {
if (err) throw err
db.batch([
{ type: 'put', key: 'gleep', value: 'gloop' },
{ type: 'put', key: 'bleep', value: 'bloop' }
], function (err) {
if (err) throw err
db.get('bleep', function (err, value) {
if (err) throw err
console.log(value)
console.log('done')
})
})
})
})