prefixdown

Prefix implemented using leveldowns

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
prefixdown
001.4.08 years ago9 years agoMinified + gzip package size for prefixdown in KB

Readme

PrefixDOWN
LevelDB sections using key prefix as a LevelUP backend.
Build Status
npm install prefixdown

By exposing a LevelDOWN compatible module, PrefixDOWN does not modify, nor set a wrapper on top of current LevelUP instance. So that it can be used on any existing LevelUP based libraries. Inspired from Subleveldown.
PrefixDOWN factory for the root LevelUP instance.

levelup(prefix, { db: prefixdown, levelup: db })

levelup(prefix, { db: prefixdown(db) })

PrefixDOWN on top of LevelUP, where location argument defines the prefix.
var levelup = require('levelup')
var prefixdown = require('prefixdown')

var db = levelup('./db') //root levelup instance

//location as prefix
var dbA = levelup('!a!', { db: prefixdown, levelup: db })
var dbB = levelup('!b!', { db: prefixdown(db) })

dbA.put('foo', 'bar', function () {
  dbB.put('foo', 'foo', function () {
    db.createReadStream().on('data', function (data) {
      //Results from root db
      {key: '!a!foo', value: 'bar'}, 
      {key: '!b!foo', value: 'foo'}
    })
  })
})

options.prefix

PrefixDOWN supports options.prefix property. A batch operation can be applied into multiple sections under the same database.
var dbA = levelup('!a!', { db: prefixdown, levelup: db })
var dbB = levelup('!b!', { db: prefixdown, levelup: db })

dbA.batch([
  {key: 'key', value: 'a', type: 'put'}, //put under dbA
  {key: 'key', value: 'b', type: 'put', prefix: dbB} //put under dbB
], ...)

License

MIT