leveldb with bytewise key encodings and bytewise friendly sublevels.
Ie. a "batteries included" distribution of levelup
that has friendly key sorting and sublevels that work with bytewise encodings.
This module is installed via npm:
$ npm install level-bytewise
var levelBytewise = require('level-bytewise');
var db = levelBytewise('/tmp/path-to-db')
var users = db.sublevel('users');
users.put(['eugene'], { color: 'black' }, function (err) {
if (err) throw err;
users.get(['eugene'], function (err, data) {
if (err) throw err;
console.log(data);
// { color: 'black }
});
});
var levelBytewise = require('level-bytewise'),
timestamp = require('monotonic-timestamp');
var db = levelBytewise('/tmp/path-to-db')
var users = db.sublevel('users');
var colors = db.sublevel('colors');
users.pre(function (change, add, batch) {
// build an index on `color` and store it in the `colors` sublevel
add({
key: [change.value.color, timestamp()],
value: change.key,
prefix: colors
});
});
users.put(['eugene'], { color: 'black' }, function (err) {
if (err) throw err;
colors.createReadStream()
.on('data', console.log);
// { key: ['black', 1461480614762], value: ['eugene'] }
});