orbitdb/examples/keyvalueReader.js
2016-04-13 09:53:03 +02:00

48 lines
1.4 KiB
JavaScript

'use strict';
const async = require('asyncawait/async');
const await = require('asyncawait/await');
const OrbitClient = require('../src/Client');
const Timer = require('./Timer');
// usage: keyvalueReader.js <host> <username> <channel> <key>
// orbit-server
const host = process.argv[2] ? process.argv[2] : 'localhost'
const port = 3333;
const username = process.argv[3] ? process.argv[3] : 'LambOfGod';
const password = '';
const channelName = process.argv[4] ? process.argv[4] : 'testing123';
const key = process.argv[5] ? process.argv[5] : 'greeting';
let run = (async(() => {
try {
const orbit = await(OrbitClient.connect(host, port, username, password));
const db = await(orbit.channel(channelName));
let count = 1;
setInterval(async(() => {
let timer = new Timer(true);
const result = db.get(key);
console.log("---------------------------------------------------")
console.log("Key | Value")
console.log("---------------------------------------------------")
console.log(`${key} | ${result}`);
console.log("---------------------------------------------------")
console.log(`Query #${count} took ${timer.stop(true)} ms\n`);
count ++;
}), 1000);
} catch(e) {
console.error("error:", e);
console.error(e.stack);
process.exit(1);
}
}))();
module.exports = run;