https://github.com/hden/rethinkdb-pool
  
  
    Connection-pool for RethinkDB 
    https://github.com/hden/rethinkdb-pool
  
connection-pool rethinkdb
        Last synced: 2 months ago 
        JSON representation
    
Connection-pool for RethinkDB
- Host: GitHub
- URL: https://github.com/hden/rethinkdb-pool
- Owner: hden
- License: mit
- Created: 2014-01-30T01:42:01.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T19:56:17.000Z (about 1 year ago)
- Last Synced: 2024-10-29T21:46:34.151Z (about 1 year ago)
- Topics: connection-pool, rethinkdb
- Language: JavaScript
- Size: 57.6 KB
- Stars: 22
- Watchers: 6
- Forks: 7
- Open Issues: 6
- 
            Metadata Files:
            - Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
 
Awesome Lists containing this project
README
          rethinkdb-pool
==============
[](https://travis-ci.org/hden/rethinkdb-pool)
[](http://badge.fury.io/js/rethinkdb-pool)
[](https://david-dm.org/hden/rethinkdb-pool)
Connection-pool for RethinkDB
[](https://github.com/feross/standard)
Installation
-----------
    npm install --save rethinkdb-pool
Usage
-----
## Create pool
```js
var r = require('rethinkdb')
var createPool = require('rethinkdb-pool')
var pool = createPool(r, {
  host:'localhost',
  port:28015,
  db:'marvel',
  authKey:'hunter2'
})
```
## Run
```js
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
```js
// 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)
    })
  })
})
```