reql-then

0.0.3 • Public • Published

ReQL, then

Promisify RethinkDB's ReQL queries. Inspired by rql-promise. Uses the bluebird promise library.

Install

npm install --save rethinkdb reql-then

Usage

var connect = require('reql-then')
  , reql = connect({
      host: 'localhost',
      port: 28015,
      db: 'test',
      authKey: '',
      maxPoolSize: 10  // set to 1 to disable connection pooling
    });
 
// Run a query
var query = r.db('MiddleEarth').table('Wizards').get('Gandalf').update({colour: 'White'});
reql(query).then(function (result) {
  // handle result
}).error(function (err) {
  // handle error
}).catch(function (err) {
  // handle exception
});
 
// Make lazy query functions
var beans = r.table('counter').get('beans')
  , add = reql.lazy(beans.update({count: r.row('count').add(1) }))
  , mul = reql.lazy(beans.update({count: r.row('count').mul(2) }))
  , sub = reql.lazy(beans.update({count: r.row('count').sub(3) }));
add().then(mul).then(sub);
 
// Disconnect
reql.close().then(function () {
  console.log('good bye');
});

Testing

Testing uses the mocha framework. A RethinkDB test server needs to be running at localhost:28015:

$ npm install -g mocha
$ rethinkdb --directory test &
$ npm test

Enable debugging messages (assuming server.js uses reql-then):

$ DEBUG=reql-then node server.js

Readme

Keywords

none

Package Sidebar

Install

npm i reql-then

Weekly Downloads

3

Version

0.0.3

License

MIT

Last publish

Collaborators

  • zaim