Comparing version 1.0.3 to 1.1.0
var genericPool = require('generic-pool') | ||
var util = require('util') | ||
var EventEmitter = require('events').EventEmitter | ||
var debug = require('debug') | ||
var objectAssign = require('object-assign') | ||
@@ -10,3 +9,3 @@ | ||
this.options = objectAssign({}, options) | ||
this.log = this.options.log || debug('pg:pool') | ||
this.log = this.options.log || function () { } | ||
this.Client = this.options.Client || Client || require('pg').Client | ||
@@ -19,2 +18,3 @@ this.Promise = this.options.Promise || Promise | ||
this.pool = new genericPool.Pool(this.options) | ||
this.onCreate = this.options.onCreate | ||
} | ||
@@ -43,2 +43,3 @@ | ||
this.log('client connected') | ||
this.emit('connect', client) | ||
if (err) { | ||
@@ -45,0 +46,0 @@ this.log('client connection error:', err) |
{ | ||
"name": "pg-pool", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Connection pool for node-postgres", | ||
@@ -39,3 +39,2 @@ "main": "index.js", | ||
"dependencies": { | ||
"debug": "^2.2.0", | ||
"generic-pool": "2.4.2", | ||
@@ -42,0 +41,0 @@ "object-assign": "4.1.0" |
# pg-pool | ||
[![Build Status](https://travis-ci.org/brianc/node-pg-pool.svg?branch=master)](https://travis-ci.org/brianc/node-pg-pool) | ||
A connection pool for node-postgres | ||
@@ -129,2 +131,50 @@ | ||
### events | ||
Every instance of a `Pool` is an event emitter. These instances emit the following events: | ||
#### error | ||
Emitted whenever an idle client in the pool encounters an error. This is common when your PostgreSQL server shuts down, reboots, or a network partition otherwise causes it to become unavailable while your pool has connected clients. | ||
Example: | ||
```js | ||
var pg = require('pg') | ||
var pool = new pg.Pool() | ||
// attach an error handler to the pool for when a connected, idle client | ||
// receives an error by being disconnected, etc | ||
pool.on('error', function(error, client) { | ||
// handle this in the same way you would treat process.on('uncaughtException') | ||
// it is supplied the error as well as the idle client which received the error | ||
}) | ||
``` | ||
#### connect | ||
Fired whenever the pool creates a __new__ `pg.Client` instance and successfully connects it to the backend. | ||
Example: | ||
```js | ||
var pg = require('pg') | ||
var pool = new pg.Pool() | ||
var count = 0 | ||
pool.on('connect', client => { | ||
client.count = count++ | ||
}) | ||
pool.connect() | ||
.then(client => { | ||
client.query('SELECT $1::int AS "clientCount', [client.count]) | ||
.then(res => console.log(res.rows[0].clientCount)) // outputs 0 | ||
})) | ||
`` | ||
This allows you to do custom bootstrapping and manipulation of clients after they have been successfully connected to the PostgreSQL backend, but before any queries have been issued. | ||
### environment variables | ||
@@ -131,0 +181,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17120
2
10
249
211
- Removeddebug@^2.2.0
- Removeddebug@2.6.9(transitive)
- Removedms@2.0.0(transitive)