Sublevels on top of
levelupwith different encodings for each sublevel.
Table of Contents
If you are upgrading: please see UPGRADING.md.
var sub =var level =var db =var test = // test is just a regular levelupvar test2 =var nested =test
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:
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.
subdb = sub(db[, prefix][, options])
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
subleveldown itself) are peeled off to get to the innermost
abstract-leveldown compliant store (like
leveldown). This ensures there is no double encoding step.
prefix must be a string. If omitted, the effective prefix is two separators, e.g.
db is already a subleveldown-powered instance, the effective prefix is a combined prefix, e.g.
options parameter has the following
subleveldown specific properties:
'!') 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
levelupinstance has been opened. The hook receives a callback which must be called to finish opening.
With npm do:
npm i subleveldown -S