Skip to content

Commit 8d6c2a4

Browse files
committed
build
1 parent e34826d commit 8d6c2a4

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

cjs/src/connection.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
109109
queue: queues.closed,
110110
idleTimer,
111111
connect(query) {
112-
initial = query || true
112+
initial = query
113113
reconnect()
114114
},
115115
terminate,
@@ -381,10 +381,13 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
381381
function errored(err) {
382382
stream && (stream.destroy(err), stream = null)
383383
query && queryError(query, err)
384-
initial && (initial.reserve ? initial.reject(err) : queryError(initial, err), initial = null)
384+
initial && (queryError(initial, err), initial = null)
385385
}
386386

387387
function queryError(query, err) {
388+
if (query.reserve)
389+
return query.reject(err)
390+
388391
if (!err || typeof err !== 'object')
389392
err = new Error(err)
390393

@@ -535,11 +538,11 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
535538
}
536539

537540
if (needsTypes) {
538-
initial === true && (initial = null)
541+
initial.reserve && (initial = null)
539542
return fetchArrayTypes()
540543
}
541544

542-
initial !== true && execute(initial)
545+
initial && !initial.reserve && execute(initial)
543546
options.shared.retries = retries = 0
544547
initial = null
545548
return

cjs/tests/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ t('Proper handling of null Errors', async() => {
445445
]
446446
})
447447

448-
t('Ensure reserve throws proper error', async() => {
448+
t('Ensure reserve on connection throws proper error', async() => {
449449
const sql = postgres({ socket: () => { throw 'wat' }, idle_timeout }) // eslint-disable-line
450450

451451
return [
@@ -2604,3 +2604,13 @@ t('arrays in reserved connection', async() => {
26042604
x.join('')
26052605
]
26062606
})
2607+
2608+
t('Ensure reserve on query throws proper error', async() => {
2609+
const sql = postgres({ idle_timeout }) // eslint-disable-line
2610+
const reserved = await sql.reserve()
2611+
const [{ x }] = await reserved`select 'wat' as x`
2612+
2613+
return [
2614+
'wat', x, reserved.release()
2615+
]
2616+
})

deno/src/connection.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
112112
queue: queues.closed,
113113
idleTimer,
114114
connect(query) {
115-
initial = query || true
115+
initial = query
116116
reconnect()
117117
},
118118
terminate,
@@ -384,10 +384,13 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
384384
function errored(err) {
385385
stream && (stream.destroy(err), stream = null)
386386
query && queryError(query, err)
387-
initial && (initial.reserve ? initial.reject(err) : queryError(initial, err), initial = null)
387+
initial && (queryError(initial, err), initial = null)
388388
}
389389

390390
function queryError(query, err) {
391+
if (query.reserve)
392+
return query.reject(err)
393+
391394
if (!err || typeof err !== 'object')
392395
err = new Error(err)
393396

@@ -538,11 +541,11 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
538541
}
539542

540543
if (needsTypes) {
541-
initial === true && (initial = null)
544+
initial.reserve && (initial = null)
542545
return fetchArrayTypes()
543546
}
544547

545-
initial !== true && execute(initial)
548+
initial && !initial.reserve && execute(initial)
546549
options.shared.retries = retries = 0
547550
initial = null
548551
return

deno/tests/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ t('Proper handling of null Errors', async() => {
447447
]
448448
})
449449

450-
t('Ensure reserve throws proper error', async() => {
450+
t('Ensure reserve on connection throws proper error', async() => {
451451
const sql = postgres({ socket: () => { throw 'wat' }, idle_timeout }) // eslint-disable-line
452452

453453
return [
@@ -2607,4 +2607,14 @@ t('arrays in reserved connection', async() => {
26072607
]
26082608
})
26092609

2610+
t('Ensure reserve on query throws proper error', async() => {
2611+
const sql = postgres({ idle_timeout }) // eslint-disable-line
2612+
const reserved = await sql.reserve()
2613+
const [{ x }] = await reserved`select 'wat' as x`
2614+
2615+
return [
2616+
'wat', x, reserved.release()
2617+
]
2618+
})
2619+
26102620
;globalThis.addEventListener("unload", () => Deno.exit(process.exitCode))

0 commit comments

Comments
 (0)