1.2.0 • Published 3 years ago

rethinkdb-pool v1.2.0

Weekly downloads
63
License
MIT
Repository
github
Last release
3 years ago

rethinkdb-pool

Build Status NPM version dependencies Status

Connection-pool for RethinkDB

js-standard-style

Installation

npm install --save rethinkdb-pool

Usage

Create pool

var r = require('rethinkdb')
var createPool = require('rethinkdb-pool')
var pool = createPool(r, {
  host:'localhost',
  port:28015,
  db:'marvel',
  authKey:'hunter2'
})

Run

var query = 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
})

Acquire / release resources

Connection can be acquired by calling the .acquire() function, but the responsibility of managing resources can be quite challenging.

See: http://bluebirdjs.com/docs/api/resource-management.html

// Don't do this! Leaks resources!
pool.acquire().then(function (connection) {
  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)
    })
  })
})
1.2.0

3 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.4.0

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.1

10 years ago