All Projects → hypermodules → Level Hookdown

hypermodules / Level Hookdown

Licence: mit
Simple levelup hooks implemented using instance method override of arbitrary levelups.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Level Hookdown

papyrusjs
papyrus.js renders maps of Minecraft: Bedrock Edition worlds using node.js, LevelDB and leaflet.
Stars: ✭ 53 (+231.25%)
Mutual labels:  leveldb
SwiftLvDB
A fast key-value storage library , leveldb for swift
Stars: ✭ 14 (-12.5%)
Mutual labels:  leveldb
Objective Leveldb
An Objective-C database library built over Google's LevelDB
Stars: ✭ 446 (+2687.5%)
Mutual labels:  leveldb
react-native-leveldown
Native bindings to LevelDB for React Native, exposed as leveldown-compatible interface
Stars: ✭ 22 (+37.5%)
Mutual labels:  leveldb
level-hyper
A convenience package bundling levelup and leveldown-hyper.
Stars: ✭ 29 (+81.25%)
Mutual labels:  leveldb
Lev
The complete REPL & CLI for managing LevelDB instances.
Stars: ✭ 295 (+1743.75%)
Mutual labels:  leveldb
pouchy
A simple, opinionated interface for PouchDB 👝
Stars: ✭ 59 (+268.75%)
Mutual labels:  leveldb
Nano Sql
Universal database layer for the client, server & mobile devices. It's like Lego for databases.
Stars: ✭ 717 (+4381.25%)
Mutual labels:  leveldb
react-isomorphic-bundle
React Redux Universal (isomorphic) bundle
Stars: ✭ 53 (+231.25%)
Mutual labels:  leveldb
Levelup
A wrapper for abstract-leveldown compliant stores, for Node.js and browsers.
Stars: ✭ 3,960 (+24650%)
Mutual labels:  leveldb
public
util toolkit for go.golang 通用函数包
Stars: ✭ 135 (+743.75%)
Mutual labels:  leveldb
level-test
Inject temporary and isolated level stores (leveldown, level-js, memdown or custom) into your tests.
Stars: ✭ 19 (+18.75%)
Mutual labels:  leveldb
Wickdb
Pure Rust LSM-tree based embedded storage engine
Stars: ✭ 298 (+1762.5%)
Mutual labels:  leveldb
LevelDBDumper
Dumps all of the Key/Value pairs from a LevelDB database
Stars: ✭ 23 (+43.75%)
Mutual labels:  leveldb
Goleveldb
LevelDB key/value database in Go.
Stars: ✭ 4,783 (+29793.75%)
Mutual labels:  leveldb
lua-leveldb
Lua bindings for google's leveldb library.
Stars: ✭ 50 (+212.5%)
Mutual labels:  leveldb
fs-changes
A persistent file system changes monitor, backed by leveldb
Stars: ✭ 12 (-25%)
Mutual labels:  leveldb
Rabbitmq Msg Store Index Eleveldb
LevelDB-based message store index for RabbitMQ
Stars: ✭ 16 (+0%)
Mutual labels:  leveldb
Leveldown
Pure C++ Node.js LevelDB binding. An abstract-leveldown compliant store.
Stars: ✭ 678 (+4137.5%)
Mutual labels:  leveldb
Pebblesdb
The PebblesDB write-optimized key-value store (SOSP 17)
Stars: ✭ 362 (+2162.5%)
Mutual labels:  leveldb

level-hookdown

Simple levelup hooks implemented using instance method override of arbitrary levelups.

npm install level-hookdown

level badge npm Build Status dependencies Status devDependencies Status

Usage

var hook = require('level-hookdown')
var mem = require('level-mem')  // or 'level' or other levelup factory
var mdb = mem()
var db = hook(mdb)

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: 'father', value: 'gloop' },
      { type: 'put', key: 'another', value: 'heep' }
    ], function (err) {
      if (err) throw err
      console.log('done')
    })
  })
})

API

hookdb = hook(db, [options])

Returns a levelup instance that executes a series of pre and post hook functions before put, del, and batch method calls. Composes well with mafintosh/subleveldown. Conflicts with dominictarr/level-sublevel.

The following options can be set when wrapping a level with hook:

{
  type: 'parallel' | 'series' | 'limit',
  limit: 5,
  protectHook: false
}
  • The type determines if the hook functions are run in series, parallel or parallel-limit. Default is parallel.
  • The limit option is passed to run-parallel-limit when type is set to limit. The default is 5.
  • protectHook performs a deep copy on the operation array in batches to preserve values if the levelup mutates them (like subleveldown does).

Hooks

hookdb.prehooks

An array of hook functions that are run before put, del, and batch method calls to the hookdb instance. If a hook function in the prehook array returns an err object to its callback, the originating put, del or batch operation will not be run on the contained db that hookdb is wrapping. A prehook veto convetion could be built on top of this behavior via error handling and retry.

hookdb.posthooks

An array of functions that are run after sucessful put, del, and batch method calls on the wrapped db instance inside a hookdb instance.

hookFn(operation, callback)

Hook functions receive an operation object that describes the level operation and a callback function.

hookdb.prehooks and hookdb.posthooks are arrays that you can add, rearrange, and delete hook functions from using standard array methods like hookdb.prehooks.push(fn) and hookdb.posthooks.pop(fn).

operation

The operation argument can contain an object that looks like:

  • {type:'put', key: 'key', value: 'value', opts}
  • {type: 'del', key: 'key', opts}
  • {type: 'batch', array: [operationArray], opts}

The opts object in the level operation object are the options that get passed through to the wrapped level.

See Also

This module is basically an alternative implementation of:

but aimed at a subleveldown workflow. These were also influential:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].