Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
level-sublevel
Advanced tools
The level-sublevel package is a plugin for LevelDB that allows you to create sublevel sections within a LevelDB database. This can help in organizing and managing data more effectively by creating isolated namespaces within the same database.
Creating Sublevels
This feature allows you to create sublevels within your LevelDB database. In the example, two sublevels 'users' and 'posts' are created, and data is added to each sublevel.
const level = require('level');
const sublevel = require('level-sublevel');
const db = level('./mydb');
const sub = sublevel(db);
const users = sub.sublevel('users');
const posts = sub.sublevel('posts');
users.put('user1', { name: 'Alice' }, function (err) {
if (err) return console.log('Ooops!', err);
console.log('User added!');
});
posts.put('post1', { title: 'Hello World' }, function (err) {
if (err) return console.log('Ooops!', err);
console.log('Post added!');
});
Batch Operations
This feature allows you to perform batch operations on a sublevel. In the example, multiple user records are added in a single batch operation.
const level = require('level');
const sublevel = require('level-sublevel');
const db = level('./mydb');
const sub = sublevel(db);
const users = sub.sublevel('users');
users.batch()
.put('user2', { name: 'Bob' })
.put('user3', { name: 'Charlie' })
.write(function (err) {
if (err) return console.log('Ooops!', err);
console.log('Batch operation complete!');
});
Stream Operations
This feature allows you to create a read stream to iterate over all entries in a sublevel. In the example, all user records are read and printed to the console.
const level = require('level');
const sublevel = require('level-sublevel');
const db = level('./mydb');
const sub = sublevel(db);
const users = sub.sublevel('users');
users.createReadStream()
.on('data', function (data) {
console.log(data.key, '=', data.value);
})
.on('error', function (err) {
console.log('Error:', err);
})
.on('end', function () {
console.log('Stream ended');
});
LevelUP is a higher-level module for working with LevelDB. It provides a more user-friendly API compared to the lower-level LevelDB bindings. While it does not provide sublevel functionality out of the box, it can be extended with plugins like level-sublevel.
Subleveldown is another package that provides sublevel functionality for LevelDB. It is similar to level-sublevel but is designed to work with the latest versions of LevelUP and LevelDB. It offers a more modern and maintained approach to creating sublevels.
Level-party is a package that allows multiple processes to safely share a single LevelDB instance. While it does not provide sublevel functionality directly, it can be used in conjunction with subleveldown or level-sublevel to achieve similar results.
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.
Unstable: Expect patches and features, possible api changes.
This is module is working well, but may change in the future as it's use is futher 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 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',
prefix: sub //NOTE pass the destination db to add
//and the value will end up in that subsection!
})
})
db.put('key', 'VALUE', function (err) {
//read all the records inserted by the hook!
sub.createReadStream()
.on('data', console.log)
})
Notice that sub
is the second argument to add
,
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.
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 104,236 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.