ti-rethinkdb-pool
v0.0.3
Published
A connection pool for RethinkDB.
Downloads
4
Maintainers
Readme
rethinkdb-pool
A Node.JS Connection Pool for RethinkDB that returns promises.
RethinkDB is Actively working on their own connection pool for all the official drivers, which is super great and once that is out you should definitely use that instead of this.
But maybe you're interested in today, not tomorrow. Me too.
Using it is easy:
var r = require('ti-rethinkdb-pool')();
r.pool.run(..your rethinkdb query here..).then(function(res) {
// do something with the result.
});
It returns a promise which you can consume however you like.
It works great with harmony node's generators & co:
var r = require('ti-rethinkdb-pool');
var co = require('co');
co(function *() {
var res = yield r.pool.run(r.table('foo'));
// do something with the result.
});
How does this differ from...
- rethinkdbdash: We use the official rethinkdb driver.
- hden's rethinkdb-pool: We return promises and you only have to carry around one
r
object, not anr
and apool
.
Also...
It automatically .toArray()
's cursors, so you should never have to deal with cursors directly, nor have to worry about releasing the pool connection after you are done with the cursor. There is currently no provision if you want to deal with cursors directly, but it looks like the official RethinkDB connection pool will.
This monkeypatches the r
namespace, which is definitely a no-no, but is also the cleanest way I could come up with to only pass around one object (r
) when making queries.
Options
var r = require('lib/rethinkdb_pool')({
host: 'localhost',
port: '28015',
db: 'test',
authKey: null,
min: 2,
max: 10
});