diff --git a/src/connection.js b/src/connection.js index 10ab1bb3..790c8772 100644 --- a/src/connection.js +++ b/src/connection.js @@ -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) diff --git a/tests/index.js b/tests/index.js index 845c6ce0..7b71cb7c 100644 --- a/tests/index.js +++ b/tests/index.js @@ -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