Skip to content

Commit 7c6f4b8

Browse files
committed
Fix connection pooling
1 parent 5fb17fb commit 7c6f4b8

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const postgres = require('postgres/cjs')
4141

4242
const sql = postgres('postgres://user:pass@host:port/database', {
4343
ssl : false, // True, or an object with options to tls.connect
44-
connections : 10, // Max number of connections
44+
max : 10, // Max number of connections
4545
timeout : 0, // Idle connection timeout in seconds
4646
types : [], // Custom types, see section below
4747
onconnect : null, // Runs before any queries on each connect

lib/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function Postgres(url, options) {
1818
let ready = false
1919
, ended = null
2020
, arrayTypesPromise
21-
, max = Math.max(1, options.connections || options.max)
21+
, max = Math.max(1, options.max)
2222
, listener
2323

2424
const connections = Queue()
@@ -152,9 +152,9 @@ export default function Postgres(url, options) {
152152
}
153153

154154
function getConnection(reserve) {
155-
const connection = connections.shift() || (--max && createConnection(options))
155+
const connection = --max >= 0 ? createConnection(options) : connections.shift()
156156
!options.fifo && !reserve && connection && connections.push(connection)
157-
connection.active = !(options.onconnect && !connection.ready)
157+
connection && (connection.active = !(options.onconnect && !connection.ready))
158158
return options.onconnect && !connection.ready
159159
? instance({ fn: options.onconnect }, connection)
160160
: connection

0 commit comments

Comments
 (0)