Skip to content

Commit 25b4644

Browse files
committed
Fix onconnect
1 parent e492370 commit 25b4644

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/connection.js

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export default function Connection(options = {}) {
140140
messages.forEach(socket.write)
141141
messages = []
142142
connection.ready = true
143+
connection.onconnect && connection.onconnect()
143144
}
144145
}
145146

lib/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,23 @@ export default function Postgres(url, options) {
180180

181181
function instance(fn, connection) {
182182
let queries = 0
183+
, container
184+
183185
addTypes(scoped, connection)
184-
const container = fn(scoped)
186+
connection.onconnect = onconnect
187+
185188
function scoped(xs, ...args) {
186189
queries++
187190
const promise = query({}, connection, xs, args)
188191
promise.then(finished, finished)
189192
return promise
190193
}
191194

195+
function onconnect() {
196+
container = fn(scoped)
197+
queries === 0 && finished(queries++)
198+
}
199+
192200
function finished() {
193201
--queries === 0 && Promise.resolve(container).then(() => {
194202
connections.push(connection)

0 commit comments

Comments
 (0)