At the application level, promises vs callbacks is yours to choose.
If you use this in a LevelUp extension that isn't explicitly about promises, nathan7 will find you and destroy you.
Play nice with the rest, use callbacks for your extension.
If your extension works with level-manifest, it'll work with this.
What it does
Every method marked as async by level-manifest will now return a promise when you don't pass it a callback. The methods that return readable streams will return streams augmented with Q's promise interface.
It recurses into sublevels.
Usage
Promises
var level =require('level')
var promisify =require('q-level')
var db =promisify(level('my.db',{ valueEncoding:'json'}))
var contents ={}
db.put('a',1)
.then(function(){
returndb.batch([
{ type:'put', key:'b', value:2},
{ type:'put', key:'c', value:3}
])
})
.then(function(){
returndb.createReadStream()
})
.progress(function(data){
contents[data.key]=data.value
})
.catch(function(err){
console.log('Error reading stream', err)
})
.then(function(){
console.log('Contents:', contents)
returndb.close()
})
.done(function(){
console.log('Closed')
})
Callbacks
same example as above, but with callbacks
var level =require('level')
var promisify =require('q-level')
var db =promisify(level('my.db'),{ valueEncoding:'json'})
var contents ={}
db.put('a',1,function(err){
db.batch([
{ type:'put', key:'b', value:2},
{ type:'put', key:'c', value:3}
],function(err){
returndb.createReadStream()
.on('data',function(data){
contents[data.key]=data.value
})
.on('error',function(err){
console.log('Error reading stream', err)
})
.on('close',function(err){
console.log('Contents:', contents)
db.close(function(err){
console.log('Closed')
})
})
})
})
Query engine support
var level =require('level')
var levelQuery =require('level-queryengine')
var jsonQueryEngine =require('jsonquery-engine')
var promisify =require('q-level')
db =levelQuery(level('my.db',{ valueEncoding:'json'}))