All Projects → Level → subleveldown

Level / subleveldown

Licence: MIT license
Split a levelup database into sublevels with their own keyspace, encoding and events.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to subleveldown

packager
A levelup package helper for distributing with an abstract-leveldown compatible back-end.
Stars: ✭ 20 (-82.91%)
Mutual labels:  level, levelup, abstract-leveldown
codec
Encode keys, values and range options, with built-in or custom encodings.
Stars: ✭ 27 (-76.92%)
Mutual labels:  level, levelup
deferred-leveldown
An abstract-leveldown implementation that queues operations while a real abstract-leveldown instance is being opened.
Stars: ✭ 18 (-84.62%)
Mutual labels:  level, abstract-leveldown
mem
A convenience package bundling levelup and memdown.
Stars: ✭ 23 (-80.34%)
Mutual labels:  level, levelup
windowed-observable
Messaging lib using a pub/sub observable scoped by namespaces.
Stars: ✭ 132 (+12.82%)
Mutual labels:  namespaces
Level Rocksdb
A convenience package bundling levelup and rocksdb.
Stars: ✭ 120 (+2.56%)
Mutual labels:  level
Esp32 I2s Slm
Sound Level Meter with ESP32 and I2S MEMS microphone
Stars: ✭ 72 (-38.46%)
Mutual labels:  level
Level Browserify
No longer maintained: superseded by level v5.0.0.
Stars: ✭ 64 (-45.3%)
Mutual labels:  level
aarbac
An Automated Role Based Access Control .NET framework with T-SQL Query Parser which automatically parse select, insert, update, delete queries based on the logged in user role
Stars: ✭ 18 (-84.62%)
Mutual labels:  level
RocketBot
An automated Pokémon Go Bot
Stars: ✭ 576 (+392.31%)
Mutual labels:  levelup
nsenter
Slim nsenter Docker image - enter into Docker container/host namespaces
Stars: ✭ 111 (-5.13%)
Mutual labels:  namespaces
Party
Open a leveldb handle multiple times
Stars: ✭ 132 (+12.82%)
Mutual labels:  level
advanced-level-editor
Advanced, but simple to use, runtime level editor for Unity.
Stars: ✭ 64 (-45.3%)
Mutual labels:  level
Electron Demo
Demo app loading LevelDB into an Electron context.
Stars: ✭ 79 (-32.48%)
Mutual labels:  level
game-map-editor
game-map-editor
Stars: ✭ 17 (-85.47%)
Mutual labels:  level
Unity Plane Mesh Splitter
Unity Plane Mesh Splitter
Stars: ✭ 71 (-39.32%)
Mutual labels:  level
strauss
Prefix PHP namespaces and classnames to allow multiple versions of libraries to exist without conflict.
Stars: ✭ 84 (-28.21%)
Mutual labels:  namespaces
Awesome
An open list of awesome Level modules and resources.
Stars: ✭ 204 (+74.36%)
Mutual labels:  level
Rocksdb
Pure C++ Node.js RocksDB binding. An abstract-leveldown compliant store.
Stars: ✭ 138 (+17.95%)
Mutual labels:  level
luxe
Luxe is a WordPress starter theme using a modern workflow and best practices.
Stars: ✭ 22 (-81.2%)
Mutual labels:  namespaces

subleveldown

Split a levelup database into sublevels with their own keyspace, encoding and events.

level badge npm Node version Test Coverage Standard Common Changelog Donate

Table of Contents

Click to expand

Usage

If you are upgrading: please see UPGRADING.md.

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

const db = level('db')
const example = sub(db, 'example')
const nested = sub(example, 'nested')

The example and nested db's are just regular levelup instances:

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

Or with promises and iterators:

await example.put('hello', 'world')
await nested.put('hi', 'welt')

for await (const [key, value] of nested.iterator()) {
  // Prints ['hi', 'welt']
  console.log([key, value])
}

Sublevels see their own keys as well as keys of any nested sublevels:

// Prints:
// { key: '!nested!hi', value: 'welt' }
// { key: 'hello', value: 'world' }
example.createReadStream().on('data', console.log)

They also support db.clear() which is very useful to empty a bucket of stuff:

example.clear(function (err) {})

// Or delete a range within `example`
example.clear({ gt: 'hello' }, function (err) {})

// With promises
await example.clear()

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). If in that case you do pass in a key that is not a string or Buffer, it will be irreversibly converted to a string.

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. Must sort before characters used in prefixes. An error will be thrown if that's not the case.
  • 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

Contributing

Level/subleveldown is an OPEN Open Source Project. This means that:

Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

See the Contribution Guide for more details.

Donate

Support us with a monthly donation on Open Collective and help us continue our work.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].