Skip to content

Instantly share code, notes, and snippets.

@techfort
Created April 12, 2015 06:18
Show Gist options
  • Save techfort/9304dadc9d2fcffdc0da to your computer and use it in GitHub Desktop.
Save techfort/9304dadc9d2fcffdc0da to your computer and use it in GitHub Desktop.
Loki2RethinkDB
var rdb = require('rethinkdb'),
loki = require('lokijs'),
db,
connection;
function forwardInsert(db, connection, table, record, callback) {
var cb = callback || function (err, obj) {
if (err) {
throw err;
}
console.log(JSON.stringify(obj, null, 2));
}
db.getCollection(table).insert(record);
console.log(db.filename, table);
rdb.db(db.filename).table(table).insert(record).run(connection, callback);
}
function run() {
var dbname = 'rethinkloki',
table = 'users',
db = new loki(dbname),
users = db.addCollection(table, {
unique: ['username']
});
rdb.connect({
host: 'localhost',
port: 28015
}, function (err, conn) {
if (err) {
console.warn(err);
throw err;
}
connection = conn;
forwardInsert(db, connection, table, {
username: 'joe',
age: 40
}, function (err, obj) {
if (err) {
throw err;
}
console.log(JSON.stringify(obj, null, 2));
console.log(users.find());
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment