Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pg-pool

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-pool - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

1

index.js

@@ -63,2 +63,3 @@ var genericPool = require('generic-pool')

this.log('acquire client')
this.emit('acquire', client)

@@ -65,0 +66,0 @@ client.release = function (err) {

2

package.json
{
"name": "pg-pool",
"version": "1.2.1",
"version": "1.3.0",
"description": "Connection pool for node-postgres",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -18,7 +18,7 @@ # pg-pool

```js
const Pool = require('pg-pool')
var Pool = require('pg-pool')
//by default the pool uses the same
//configuration as whatever `pg` version you have installed
const pool = new Pool()
var pool = new Pool()

@@ -29,3 +29,3 @@ //you can pass properties to the pool

//allowing you to fully configure the behavior of both
const pool2 = new Pool({
var pool2 = new Pool({
database: 'postgres',

@@ -43,8 +43,8 @@ user: 'brianc',

//if you want to use the native postgres client
const NativeClient = require('pg').native.Client
const nativePool = new Pool({ Client: NativeClient })
var NativeClient = require('pg').native.Client
var nativePool = new Pool({ Client: NativeClient })
//you can even pool pg-native clients directly
const PgNativeClient = require('pg-native')
const pgNativePool = new Pool({ Client: PgNativeClient })
var PgNativeClient = require('pg-native')
var pgNativePool = new Pool({ Client: PgNativeClient })
```

@@ -57,3 +57,3 @@

```js
const pool = new Pool()
var pool = new Pool()
pool.connect().then(client => {

@@ -78,6 +78,6 @@ client.query('select $1::text as name', ['pg-pool']).then(res => {

(async () => {
const pool = new Pool()
const client = await pool.connect()
var pool = new Pool()
var client = await pool.connect()
try {
const result = await client.query('select $1::text as name', ['brianc'])
var result = await client.query('select $1::text as name', ['brianc'])
console.log('hello from', result.rows[0])

@@ -91,5 +91,5 @@ } finally {

co(function * () {
const client = yield pool.connect()
var client = yield pool.connect()
try {
const result = yield client.query('select $1::text as name', ['brianc'])
var result = yield client.query('select $1::text as name', ['brianc'])
console.log('hello from', result.rows[0])

@@ -107,5 +107,5 @@ } finally {

```js
const pool = new Pool()
const time = await pool.query('SELECT NOW()')
const name = await pool.query('select $1::text as name', ['brianc'])
var pool = new Pool()
var time = await pool.query('SELECT NOW()')
var name = await pool.query('select $1::text as name', ['brianc'])
console.log(name.rows[0].name, 'says hello at', time.rows[0].name)

@@ -117,3 +117,3 @@ ```

```js
const pool = new Pool()
var pool = new Pool()
pool.query('SELECT $1::text as name', ['brianc'], function (err, res) {

@@ -134,3 +134,3 @@ console.log(res.rows[0].name) // brianc

```js
const pool = new Pool()
var pool = new Pool()
pool.connect((err, client, done) => {

@@ -155,4 +155,4 @@ if (err) return done(err)

```js
const pool = new Pool()
const client = await pool.connect()
var pool = new Pool()
var client = await pool.connect()
console.log(await client.query('select now()'))

@@ -172,3 +172,3 @@ client.release()

// 'globally' here, controlling access to it through exported methods
const pool = new pg.Pool()
var pool = new pg.Pool()

@@ -187,3 +187,3 @@ // this is the right way to export the query method

// number of pools & therefore connections
const aPool = new pg.Pool()
var aPool = new pg.Pool()
return aPool.connect()

@@ -204,4 +204,4 @@ }

```js
var pg = require('pg')
var pool = new pg.Pool()
const Pool = require('pg-pool')
const pool = new Pool()

@@ -223,4 +223,4 @@ // attach an error handler to the pool for when a connected, idle client

```js
var pg = require('pg')
var pool = new pg.Pool()
const Pool = require('pg-pool')
const pool = new Pool()

@@ -237,6 +237,6 @@ var count = 0

return client
.query('SELECT $1::int AS "clientCount', [client.count])
.query('SELECT $1::int AS "clientCount"', [client.count])
.then(res => console.log(res.rows[0].clientCount)) // outputs 0
.then(() => client)
}))
})
.then(client => client.release())

@@ -246,4 +246,35 @@

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.
#### acquire
Fired whenever the a client is acquired from the pool
Example:
This allows you to count the number of clients which have ever been acquired from the pool.
```js
var Pool = require('pg-pool')
var pool = new Pool()
var acquireCount = 0
pool.on('acquire', function (client) {
acquireCount++
})
var connectCount = 0
pool.on('connect', function () {
connectCount++
})
for (var i = 0; i < 200; i++) {
pool.query('SELECT NOW()')
}
setTimeout(function () {
console.log('connect count:', connectCount) // output: connect count: 10
console.log('acquire count:', acquireCount) // output: acquire count: 200
}, 100)
```
### environment variables

@@ -250,0 +281,0 @@

@@ -24,2 +24,23 @@ var expect = require('expect.js')

})
it('emits acquire every time a client is acquired', function (done) {
var pool = new Pool()
var acquireCount = 0
pool.on('acquire', function (client) {
expect(client).to.be.ok()
acquireCount++
})
for (var i = 0; i < 10; i++) {
pool.connect(function (err, client, release) {
err ? done(err) : release()
release()
if (err) return done(err)
})
pool.query('SELECT now()')
}
setTimeout(function () {
expect(acquireCount).to.be(20)
pool.end(done)
}, 40)
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc