Coder Social home page Coder Social logo

rethinkdb-pool's Introduction

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)
    })
  })
})

rethinkdb-pool's People

Contributors

cartor avatar dotcypress avatar hden avatar hori-ryota avatar minibikini avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rethinkdb-pool's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • generic-pool 3.7.8
  • intelli-espower-loader 1.1.0
  • mocha 8.3.2
  • power-assert 1.6.1
  • rethinkdb 2.4.2
  • standard 16.0.3
travis
.travis.yml

  • Check this box to trigger a request for Renovate to run again on this repository

Cannot read property 'table' of undefined

 var r    = require('rethinkdb');
 var Pool = require('rethinkdb-pool');

 var pool = Pool({
     host:rHost,
     port:rPort,
     db:'Unnyworld',
     r: r
 });

But when trying to make query:

 var addPlayer = pool.r.table(TABLE_PLAYERS).insert(player, {conflict: "replace"});

got error:

 var addPlayer = pool.r.table(TABLE_PLAYERS).insert(player, {conflict: 
                       ^
 TypeError: Cannot read property 'table' of undefined

Update generic-pool dependency

Hi, I really appreciated your work.

Do you think it is possible to update your generic-pool dependency ?

There is a migration guide here

If you don't have time now, I would be glad to do it myself and drop you a PR. I may be able to do the PR in one or two weeks.

And happy new year ! ๐ŸŽ‰

pool.run returns error when query returns `null`

For instance

var query = pool.r.table('sometable').get('this_key_does_not_exist');
pool.run(query, function (error, ret) {
    if (error !== null) {
        console.error("DB ERROR: " + error);
        return handleError(socket, error);
    }
    // ...
});

prints ERROR TypeError: Cannot read property 'toArray' of null while the expected behaviour is null in both ret and error.

I think this is because cursorOrResult.toArray (https://github.com/hden/rethinkdb-pool/blob/master/index.js#L50) doesn't work with null.

Connection errors

How to check connection error(wrong host/port/password) on createPool?

Unable to instal the package

I'm new to node and to me this error does not make any sense:

npm ERR! Darwin 14.0.0
npm ERR! argv "node" "/usr/local/bin/npm" "install"
npm ERR! node v0.10.33
npm ERR! npm  v2.1.12
npm ERR! code ETARGET

npm ERR! notarget No compatible version found: rethinkdb@'>=1.14.0 <1.15.0'
npm ERR! notarget Valid install targets:
npm ERR! notarget ["1.2.0-0","1.2.5-0","1.2.6-0","1.2.6-1","1.4.0-0","1.4.0-1","1.4.0-2","1.4.0-3","1.5.0-0","1.6.0-0","1.7.0-1","1.7.0-2","1.8.0-0","1.9.0-0","1.9.0-1","1.10.0-0","1.11.0-0","1.11.0-1","1.11.0-2","1.11.0-3","1.11.0-4","1.12.0-0","1.12.0-1","1.13.0-0","1.13.0-1","1.13.0-2","1.13.0-3","1.14.0-0","1.15.0-0"]
npm ERR! notarget 

Seems like npm is unable to match 1.14.0 with 1.14.0-0. I've managed to install pure rethinkdb package only by specifying a full version.

BTW how about upgrading rethinkdb dep up to 1.15?

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Example with middleware?

Can we see an example with middleware? Specifically, I'm not sure how to best release resources with Express middleware, since most routes finish their work and don't call next() to continue more middleware.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.