Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,12 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
: (query = q, query.active = true)

build(q)
return write(toBuffer(q))
const written = write(toBuffer(q))
written && q.options.onexecute && q.options.onexecute(connection)
return written
&& !q.describeFirst
&& !q.cursorFn
&& sent.length < max_pipeline
&& (!q.options.onexecute || q.options.onexecute(connection))
} catch (error) {
sent.length === 0 && write(Sync)
errored(error)
Expand Down
21 changes: 21 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,27 @@ t('Helpers in Transaction', async() => {
))[0].x]
})

t('Transaction works with max_pipeline 0', async() => {
const sql = postgres({ ...options, max: 4, max_pipeline: 0 })
return [1, (await sql.begin(sql => sql`select 1 as x`))[0].x, await sql.end()]
})

t('Transaction with sequential queries works with max_pipeline 0', async() => {
const sql = postgres({ ...options, max: 4, max_pipeline: 0 })
return ['testing', await sql.begin(async sql => {
await sql`select set_config('postgres_js.test', 'testing', true)`
return (await sql`select current_setting('postgres_js.test') as x`)[0].x
}), await sql.end()]
})

t('Transaction with concurrent queries works with max_pipeline 0', async() => {
const sql = postgres({ ...options, max: 4, max_pipeline: 0 })
return ['testing', (await sql.begin(sql => [
sql`select set_config('postgres_js.test', 'testing', true)`,
sql`select current_setting('postgres_js.test') as x`
]))[1][0].x, await sql.end()]
})

t('Undefined values throws', async() => {
let error

Expand Down