![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
level-sublevel
Advanced tools
Separate sections of levelup, with hooks!
This module allows you to create seperate sections of a levelup database, kinda like tables in an sql database, but evented, and ranged, for real-time changing data.
The long awaited level-sublevel
rewrite is out!
You are hearby warned this is a significant breaking change.
So it's good to use it with a new project,
The user api is mostly the same as before,
but the way that keys are encoded has changed, and this means
you cannot run 6 on a database you created with 5.
Also, createWriteStream
has been removed, in anticipation of this
change use something
like level-write-stream
Using leveldb with legacy mode is the simplest way to get the new sublevel on top of a database that used old sublevel. Simply require sublevel like this:
var level = require('level')
// V *** require legacy.js ***
var sublevel = require('level-sublevel/legacy')
var db = sublevel(level(path))
@calvinmetcalf has created a migration tool: sublevel-migrate
This can be used to copy an old level-sublevel into the new format.
Unstable: Expect patches and features, possible api changes.
This module is working well, but may change in the future as its use is further explored.
var LevelUp = require('levelup')
var Sublevel = require('level-sublevel')
var db = Sublevel(LevelUp('/tmp/sublevel-example'))
var sub = db.sublevel('stuff')
//put a key into the main levelup
db.put(key, value, function () {})
//put a key into the sub-section!
sub.put(key2, value, function () {})
Sublevel prefixes each subsection so that it will not collide with the outer db when saving or reading!
Hooks are specially built into Sublevel so that you can do all sorts of clever stuff, like generating views or logs when records are inserted!
Records added via hooks will be atomically inserted with the triggering change.
Whenever a record is inserted, save an index to it by the time it was inserted.
var sub = db.sublevel('SEQ')
db.pre(function (ch, add) {
add({
key: ''+Date.now(),
value: ch.key,
type: 'put',
// NOTE: pass the destination db to add the value to that subsection!
prefix: sub
})
})
db.put('key', 'VALUE', function (err) {
// read all the records inserted by the hook!
sub.createReadStream().on('data', console.log)
})
Notice that the prefix
property to add()
is set to sub
, which tells the hook to save the new record in the sub
section.
In sublevel
batches also support a prefix: subdb
property,
if set, this row will be inserted into that database section,
instead of the current section, similar to the pre
hook above.
var sub1 = db.sublevel('SUB_1')
var sub2 = db.sublevel('SUM_2')
sub.batch([
{key: 'key', value: 'Value', type: 'put'},
{key: 'key', value: 'Value', type: 'put', prefix: sub2},
], function (err) {...})
MIT
FAQs
partition levelup databases
The npm package level-sublevel receives a total of 141,142 weekly downloads. As such, level-sublevel popularity was classified as popular.
We found that level-sublevel demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.