rethinkdb-pool

Connection-pool for RethinkDB

rethinkdb-pool

Connection-pool for RethinkDB

npm install --save rethinkdb-pool
// run node with --harmony to use built-in Promise
// or require any compatible library of your choise
var r    = require('rethinkdb')
var Pool = require('rethinkdb-pool');
var pool = Pool({
  host:'localhost',
  port:28015,
  db:'marvel',
  authKey:'hunter2',
  r: r,
  Promise: Promise
});
pool.acquire(function (error, connection) {
  if (error != null) {
    return handleError(error);
  }
  r.table('aTable').limit(10).run(connection, function (error, cursor) {
    if (error != null) {
      return handleError(error);
    }
    cursor.toArray(function (error, data) {
      if (error != null) {
        return handleError(error);
      }
      console.log(data);
      pool.release(connection);
    });
  });
});
var query = pool.r.table('foo').limit(100);

// callback
pool.run(query, function (error, list) {
  // no more acquire, no more toArray, yay!!
});

// promise
pool.run(query).then(function (list) {
  // promise, yay
});