2.0.1 • Published 10 years ago
level-promisify v2.0.1
Level-promisify
Leveldb with promises
Skinny wrapper around leveldb that adds promises instead of callbacks.
Getting Started
Installation
npm i -S level-promisifyThe constructor takes one argument, the leveldb instance to use.
var level = require( 'level' )( path );
var db = require( 'level-promisify' )( level );
db.put( 'foo', 'bar' )
.then( function() {
db.get( 'foo' )
.then( function( res ) {
console.log( res ); // 'bar'
})
})
.catch( function( err ) {
console.log( err );
});API
putgetdelbatchArray form
The API doesn’t change, you just handle the responses using promises.
If you want access to the underlying database then it’s exposed via db.root, for example, if you pass it a db using the hooks plugin then that’s still available:
var level = require( 'level' )( path );
var hookdb = require( 'level-hooks' )( db );
var db = require( 'level-promisify' )( hookdb );
db.root.hooks.pre( … );