Skip to content

Instantly share code, notes, and snippets.

@alessioalex alessioalex/client.js Secret
Last active Dec 26, 2015

Embed
What would you like to do?
multilevel and sublevel working
var multilevel = require('multilevel');
var net = require('net');
var after = require('after');
var Sublevel = require('level-sublevel');
var manifest = require('./manifest.json');
var db = multilevel.client(manifest);
var con = net.connect(3000);
con.pipe(db.createRpcStream()).pipe(con);
// not sure if this is correct.. ?
var stuffDb = db.sublevel('stuff');
var preDb = db.sublevel('pre');
preDb.put('heyyy', { value: 'there' }, function(err) {
// the pre hook should be executed on the server, shouldn't it?
if (err) { throw err; }
});
var multilevel = require('multilevel');
var net = require('net');
var level = require('level');
var Sublevel = require('level-sublevel');
var port = 3000;
var db = Sublevel(level(__dirname + '/mydb', { valueEncoding: 'json' }));
// so I want to use these 2 sublevels on the client
var stuff = db.sublevel('stuff');
var preDb = db.sublevel('pre');
preDb.pre(function (ch, add) {
console.log('OK this should be called once');
});
// now write the manifest to a file
multilevel.writeManifest(db, __dirname + '/manifest.json');
net.createServer(function (con) {
con.on('data', function(data) {
// console.log(data.toString());
// console.log('------------------------------');
});
con.pipe(multilevel.server(db)).pipe(con);
}).listen(port);
console.log('Multilevel server started on port %s', port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.