A module to save a document into leveldb where the old indexes are removed in the same batch as the new ones are inserted
It loads the old document and creates a single batch of 'del' and 'put' commands from the mapper function you provide.
It can also expand a batch of multiple documents into a single larger batch containing the index 'put' and 'del' commands for each document.
This is a cumbersome way to do it and there are limitations but hey - life is short and suggestions (like how to manage an immutable collection of indexes for changing values) are welcome : )
var level = ;var sub = ;var indexupdate = ;var db =var indexer =indexer
You can also insert a batch of documents and it will auto-expand the batch for the indexes:
var indexer = indexupdate(db, [indexpath], mapper)
Create an updater function by passing a leveldb, an optional path to write the indexes (defaults to 'updateindex') and a mapper function that will emit the index fields and values for each value
indexer.save(key, value, callback(err, batch))
Run the updater function by passing the key and the value for the update.
The callback will be passed the batch that was inserted into the database.
indexer.expandBatch(arr, callback(err, batch))
Pass a batch of commands and it will convert into a larger batch with all the indexes for each 'put' and 'del' resolved.
indexer.batch(arr, callback(err, batch))
Uses expandBatch and then actually runs the batch
mapper(key, value, emit([values], manualkey))
The mapper function is called for each update - once for the old values and once for the new values
Call emit with an array of values to index based on the passed object
You can call emit many times per object - the key will be added to the index entry automatically
Pass an array of values to the indexer - the key will automatically be appended.
If you want to manually manage the index but still want the batch behavious, pass true as the second argument to emit:
var indexer =
- handle if a save request for a key arrives whilst another is resolving