Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
subleveldown
Advanced tools
Sublevels on top of
levelup
with different encodings for each sublevel.
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)
})
})
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.
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.
With npm do:
npm i subleveldown -S
MIT © 2014-present Mathias Buus and contributors. See the included LICENSE file for more details.
[3.0.0-rc1] - 2018-06-03
levelup
from ^1.2.1
to ^3.0.1
(@ralphtheninja)abstract-leveldown
from ^2.4.1
to ^5.0.0
(@ralphtheninja)memdown
devDependency from ^1.1.0
to ^3.0.0
(@ralphtheninja)tape
devDependency from ^4.2.2
to ^4.9.0
(@ralphtheninja)standard
devDependency from ^5.3.1
to ^11.0.1
(@ralphtheninja)package.json
(@ralphtheninja)util.inherits
with inherits
module (@ralphtheninja)SubIterator
should inherit from AbstractIterator
(@ralphtheninja)SubDown#type
from subdown
to subleveldown
(@ralphtheninja)SubDown#_open
to handle any inner *downs (@ralphtheninja)levelup
+ encoding-down
(@ralphtheninja)encoding-down
for encoding logic (@ralphtheninja)SubDown
constructor (@ralphtheninja)levelup
and re-opening it (@ralphtheninja)down()
and isAbstract()
functions (@ralphtheninja)UPGRADING.md
(@ralphtheninja)SubDown#destroy
(@ralphtheninja)SubDown#repair
(@ralphtheninja)SubDown#setDb
(@ralphtheninja)SubDown#approximateSize
(@ralphtheninja)SubDown#getProperty
(@ralphtheninja)new Buffer()
(@ralphtheninja)FAQs
Split a levelup database into sublevels with their own keyspace, encoding and events
The npm package subleveldown receives a total of 55,604 weekly downloads. As such, subleveldown popularity was classified as popular.
We found that subleveldown demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.