level-map-index

0.1.0 • Public • Published

level-map-index

Another indexing solution for leveldb. Adapted from map-reduce. The API is unstable because this module is a by-product of refactoring an ugly ORM.

npm status Stability Travis build status AppVeyor build status Dependency status

Jump to: api / install / license

examples

// create your database
var sublevel = require('level-sublevel')
  , level = require('levelup')
  , db = sublevel(level('./data'), {valueEncoding: 'json'})
 
// install
require('level-map-index')(db)
 
// create indices
db.index('title')
db.index(['author.name', 'price'])
 
// a custom index (should return an array)
db.index('custom', function map(key, value){
  return [value.title.indexOf('f')]
})
 
var author = { name: 'bob' }
var book   = { title: 'foo', price: 10, author: author }
 
db.put('foo', book, search)
 
function search() {
  // streams will wait for indexing to complete
 
  // every book by bob, ordered by price
  db.streamBy(['author.name', 'price'], 'bob').pipe(somewhere)
 
  // every book by bob with a price of 10
  db.streamBy(['author.name', 'price'], ['bob', 10]).pipe(somewhere)
 
  // ordered by title
  db.streamBy('title').pipe(somewhere)
 
  // use sublevel hooks
  db.index('custom').post(function(op){
    // op.key is the array we returned from our `map` fn above
    if (op.type=='del' && op.key[0]===0) {
      console.log('no more titles starting with "f" in our db')
    }
  })
 
  // this will (eventually) trigger the above post hook
  db.del('a')
}

api

index (db, [opts || fn])

Install the plugin.

db.index(props, [opts || fn])

Create an index.

db.streamBy(props, [range, opts])

Likely to change, no docs yet.

db.by(props, [range, opts], cb)

db.getBy(props, [range, opts], cb)

db.hasIndex(props)

index.start()

Manually trigger a rebuild. A complete event fires when it's done.

install

With npm do:

npm install level-map-index

license

MIT © Dominic Tarr, Vincent Weevers

Readme

Keywords

Package Sidebar

Install

npm i level-map-index

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • vweevers