Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hden/rethinkdb-pool
Connection-pool for RethinkDB
https://github.com/hden/rethinkdb-pool
connection-pool rethinkdb
Last synced: 14 days 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 11 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T19:56:17.000Z (2 months ago)
- Last Synced: 2024-10-29T21:46:34.151Z (2 months 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
==============[![Build Status](https://travis-ci.org/hden/rethinkdb-pool.svg?branch=master)](https://travis-ci.org/hden/rethinkdb-pool)
[![NPM version](https://badge.fury.io/js/rethinkdb-pool.svg)](http://badge.fury.io/js/rethinkdb-pool)
[![dependencies Status](https://david-dm.org/hden/rethinkdb-pool/status.svg)](https://david-dm.org/hden/rethinkdb-pool)Connection-pool for RethinkDB
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](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)
})
})
})
```