subleveldown

sublevels implemented using leveldowns

Superseded by abstract-level (https://github.com/Level/community#faq)
Last updated 8 years ago by ralphtheninja .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install subleveldown 
SYNC missed versions from official npm registry.

subleveldown

Sublevels on top of levelup with different encodings for each sublevel.

level badge npm Node version Travis dependencies npm JavaScript Style Guide

Table of Contents

<summary>Click to expand</summary>

Usage

If you are upgrading: please see UPGRADING.md.

var sub = require('subleveldown')
var level = require('level')

var db = level('db')

var test = sub(db, 'test') // test is just a regular levelup
var test2 = sub(db, 'test2')
var nested = sub(test, 'nested')

test.put('hello', 'world', function() {
  nested.put('hi', 'welt', function() {
    // will print {key:'hello', value:'world'}
    test.createReadStream().on('data', console.log)
  })
})

Background

subleveldown separates a levelup database into sections - or sublevels from here on out. Think SQL tables, but evented, ranged and realtime!

Each sublevel is a levelup of its own. This means it has the exact same interface as its parent database, but its own keyspace and events. In addition, sublevels are individually wrapped with encoding-down, giving us per-sublevel encodings. For example, it's possible to have one sublevel with Buffer keys and another with 'utf8' encoded keys. The same goes for values. Like so:

sub(db, 'one', { valueEncoding: 'json' })
sub(db, 'two', { keyEncoding: 'binary' })

There is one limitation, however: keys must encode to either strings or Buffers. This is not likely to affect you, unless you use custom encodings or the id encoding (which bypasses encodings and thus makes it your responsibility to ensure keys are either strings or Buffers).

Authored by @mafintosh and inspired by level-sublevel by @dominictarr, subleveldown has become an official part of Level. As level-sublevel is no longer under active development, we recommend switching to subleveldown to get the latest and greatest of the Level ecosystem. These two modules largely offer the same functionality, except for hooks and per-batch prefixes.

API

subdb = sub(db[, prefix][, options])

Returns a levelup instance that uses subleveldown to prefix the keys of the underlying store of db. The required db parameter must be a levelup instance. Any layers that this instance may have (like encoding-down or subleveldown itself) are peeled off to get to the innermost abstract-leveldown compliant store (like leveldown). This ensures there is no double encoding step.

The prefix must be a string. If omitted, the effective prefix is two separators, e.g. '!!'. If db is already a subleveldown-powered instance, the effective prefix is a combined prefix, e.g. '!one!!two!'.

The optional options parameter has the following subleveldown specific properties:

  • separator (string, default: '!') Character for separating sublevel prefixes from user keys and each other. Should be outside the character (or byte) range of user keys.
  • open (function) Optional open hook called when the underlying levelup instance has been opened. The hook receives a callback which must be called to finish opening.

Any other options are passed along to the underlying levelup and encoding-down constructors. See their documentation for further details.

Install

With npm do:

npm i subleveldown -S

License

MIT © 2014-present Mathias Buus and contributors. See the included LICENSE file for more details.

Current Tags

  • 6.0.1                                ...           latest (5 years ago)

23 Versions

  • 6.0.1 [deprecated]           ...           5 years ago
  • 6.0.0 [deprecated]           ...           5 years ago
  • 5.0.1 [deprecated]           ...           6 years ago
  • 5.0.0 [deprecated]           ...           7 years ago
  • 4.1.4 [deprecated]           ...           7 years ago
  • 4.1.3 [deprecated]           ...           7 years ago
  • 4.1.2 [deprecated]           ...           7 years ago
  • 4.1.1 [deprecated]           ...           7 years ago
  • 4.1.0 [deprecated]           ...           7 years ago
  • 4.0.0 [deprecated]           ...           8 years ago
  • 3.0.1 [deprecated]           ...           8 years ago
  • 3.0.0 [deprecated]           ...           8 years ago
  • 3.0.0-rc1 [deprecated]           ...           8 years ago
  • 2.1.0 [deprecated]           ...           11 years ago
  • 2.0.0 [deprecated]           ...           12 years ago
  • 1.1.0 [deprecated]           ...           12 years ago
  • 1.0.6 [deprecated]           ...           12 years ago
  • 1.0.5 [deprecated]           ...           12 years ago
  • 1.0.4 [deprecated]           ...           12 years ago
  • 1.0.3 [deprecated]           ...           12 years ago
  • 1.0.2 [deprecated]           ...           12 years ago
  • 1.0.1 [deprecated]           ...           12 years ago
  • 1.0.0 [deprecated]           ...           12 years ago
Downloads
Total 65
Today 0
This Week 0
This Month 40
Last Day 0
Last Week 11
Last Month 2
Dependencies (5)
Dev Dependencies (3)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE