1.4.0 • Published 9 years ago

prefixdown v1.4.0

Weekly downloads
64
License
MIT
Repository
github
Last release
9 years ago

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

1.4.0

9 years ago

1.3.2

10 years ago

1.3.1

10 years ago

1.3.0

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.6

10 years ago

1.1.5

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago

0.1.0

10 years ago