npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rpool

v1.0.1

Published

RethinkDB connection pool

Downloads

72

Readme

Build Status NPM Version js-standard-style

rpool

RethinkDB connection pool.

Installation

$ npm install --save rpool

API

Create pool

rpool(r, dbOptions, poolOptions) -> Pool

  • r - RethinkDB reference
  • dbOptions | dbOptions[] - RethinkDB options
    • url: Connection string/array of strings. If present will silentry rewrite connections options(host, port, etc.)
    • host: the host to connect to (default localhost).
    • port: the port to connect on (default 28015).
    • db: the default database (default test).
    • See RethinkDB docs for additional options.
  • poolOptions - Pool options
    • min: minimum number of connections to keep in pool at any given time. If this is set >= max, the pool will silently set the min to equal max. (default 1)
    • max: maximum number of connections. (default 10)
    • testOnBorrow: should the pool validate resources before giving them to clients. (default true)
    • acquireTimeoutMillis: max milliseconds an acquire call will wait for a resource before timing out. (default 10 seconds), if supplied should non-zero positive integer.
    • See generic-pool docs.

Example:

const r = require('rethinkdb')
const rpool = require('rpool')

const pool = rpool(r, 'rethinkdb://localhost:32779/foo')
const pool = rpool(r, ['rethinkdb://portal-1:32779/foo', 'rethinkdb://portal-2:32779/foo'])
const pool = rpool(r, 'rethinkdb://localhost:32779/foo', { max: 100, acquireTimeoutMillis: 5000 })
const pool = rpool(r, { url: 'rethinkdb://localhost:32779', db: 'bar' }, { max: 100 })
const pool = rpool(r, { host: 'localhost', port: '32779', db: 'foo' }, { max: 10 })
const pool = rpool(r, [
  { url: 'rethinkdb://portal-1:32779/bar',' }
  { url: 'rethinkdb://portal-2:32779', db: 'bar' }
], { max: 100 })

Acquire / release connections

pool.acquire(priority) -> Promise<#{connection, release}>

  • priority: optional priority.

Example:

const r = require('rethinkdb')
const rpool = require('rpool')

const pool = rpool(r, 'rethinkdb://localhost:32779/foo')

pool.acquire().then(({ connection, release }) => {
  r.table('users')
    .run(connection)
    .then((cursor) => {
      console.log('Cursor:', cursor)
    })
    .catch((err) => {
      console.log(err)
    })
    .then(release)
})

Run queries

pool.run(query, options) -> Promise<QueryResult>

  • query: RethinkDB query or query builder function.
  • options: Run option.

⚠️ Note: All cursors are automatically converted into arrays.

Example:

const r = require('rethinkdb')
const rpool = require('rpool')

const pool = rpool(r, 'rethinkdb://localhost:32779/foo')

pool.run(r.table('users')).then((users) => {
  console.log('Users:', users)
})

pool.run((r) => r.table('users')).then((users) => {
  console.log('Users:', users)
})

const deleteQuery = r.table('users').get('user_id').delete()
pool.run(deleteQuery)