Map Reduce for leveldb (via levelup)
Incremental map-reduces and real-time results.
Waat?
An "incremental map reduce" means when you update one key,
only a relevant protion of the data needs to be recalculated.
"real-time results" means that you can listen to the database,
and recieve change notifications on the fly! a la
level-live-stream
Example
var levelup = require('levelup')
levelup(flie, {createIfMissing:true}, function (err, db) {
require('map-reduce')([{
name : 'example',
start : '',
end : '~',
map : function (key, value, emit) {
var obj = JSON.parse(value)
emit(['all', obj.group], ''+obj.lines.length)
},
reduce: function (big, little, key) {
return return ''+(Number(big) + Number(little))
},
initial: '0'
}]) (db)
})
map-reduce
uses level-hooks
and level-queue to make map reduces durable.
querying results.
db.mapReduce.view(viewName, {start: ['all', group]})
db.mapReduce.view(viewName, {start: ['all', true]})
db.mapReduce.view(viewName, {start: []})
db.mapReduce.view(viewName, {start: ['all', group1], end: ['all', groupN]})
db.mapReduce.view()
returns an instance of
level-live-stream
If you do not want a live-stream, pass {tail:false}
db.mapReduce.view(viewName, {start: ['all', true], tail: false})
License
MIT