From f82ca1b85345650d5063745d80a61ac207826de1 Mon Sep 17 00:00:00 2001 From: Rasmus Porsager Date: Wed, 20 Mar 2024 21:02:54 +0100 Subject: [PATCH] Properly check if prepared --- cjs/src/connection.js | 2 +- cjs/tests/index.js | 13 +++++++++++-- deno/src/connection.js | 2 +- deno/tests/index.js | 13 +++++++++++-- src/connection.js | 2 +- tests/index.js | 13 +++++++++++-- 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/cjs/src/connection.js b/cjs/src/connection.js index 9180693d..10184ca3 100644 --- a/cjs/src/connection.js +++ b/cjs/src/connection.js @@ -788,7 +788,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose const error = Errors.postgres(parseError(x)) query && query.retried ? errored(query.retried) - : query && query.prepare && retryRoutines.has(error.routine) + : query && query.prepared && retryRoutines.has(error.routine) ? retry(query, error) : errored(error) } diff --git a/cjs/tests/index.js b/cjs/tests/index.js index 437ed2f9..d49c7dcf 100644 --- a/cjs/tests/index.js +++ b/cjs/tests/index.js @@ -1789,14 +1789,14 @@ t('Recreate prepared statements on RevalidateCachedQuery error', async() => { ] }) -t('Properly throws routing error on not prepared statements', async() => { +t('Properly throws routine error on not prepared statements', async() => { await sql`create table x (x text[])` const { routine } = await sql.unsafe(`insert into x(x) values (('a', 'b'))`).catch(e => e) return ['transformAssignedExpr', routine, await sql`drop table x`] }) -t('Properly throws routing error on not prepared statements in transaction', async() => { +t('Properly throws routine error on not prepared statements in transaction', async() => { const { routine } = await sql.begin(sql => [ sql`create table x (x text[])`, sql`insert into x(x) values (('a', 'b'))`, @@ -1805,6 +1805,15 @@ t('Properly throws routing error on not prepared statements in transaction', asy return ['transformAssignedExpr', routine] }) +t('Properly throws routine error on not prepared statements using file', async() => { + const { routine } = await sql.unsafe(` + create table x (x text[]); + insert into x(x) values (('a', 'b')); + `, { prepare: true }).catch(e => e) + + return ['transformAssignedExpr', routine] +}) + t('Catches connection config errors', async() => { const sql = postgres({ ...options, user: { toString: () => { throw new Error('wat') } }, database: 'prut' }) diff --git a/deno/src/connection.js b/deno/src/connection.js index 2722095c..81f26c08 100644 --- a/deno/src/connection.js +++ b/deno/src/connection.js @@ -791,7 +791,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose const error = Errors.postgres(parseError(x)) query && query.retried ? errored(query.retried) - : query && query.prepare && retryRoutines.has(error.routine) + : query && query.prepared && retryRoutines.has(error.routine) ? retry(query, error) : errored(error) } diff --git a/deno/tests/index.js b/deno/tests/index.js index 55581c42..055f479b 100644 --- a/deno/tests/index.js +++ b/deno/tests/index.js @@ -1791,14 +1791,14 @@ t('Recreate prepared statements on RevalidateCachedQuery error', async() => { ] }) -t('Properly throws routing error on not prepared statements', async() => { +t('Properly throws routine error on not prepared statements', async() => { await sql`create table x (x text[])` const { routine } = await sql.unsafe(`insert into x(x) values (('a', 'b'))`).catch(e => e) return ['transformAssignedExpr', routine, await sql`drop table x`] }) -t('Properly throws routing error on not prepared statements in transaction', async() => { +t('Properly throws routine error on not prepared statements in transaction', async() => { const { routine } = await sql.begin(sql => [ sql`create table x (x text[])`, sql`insert into x(x) values (('a', 'b'))`, @@ -1807,6 +1807,15 @@ t('Properly throws routing error on not prepared statements in transaction', asy return ['transformAssignedExpr', routine] }) +t('Properly throws routine error on not prepared statements using file', async() => { + const { routine } = await sql.unsafe(` + create table x (x text[]); + insert into x(x) values (('a', 'b')); + `, { prepare: true }).catch(e => e) + + return ['transformAssignedExpr', routine] +}) + t('Catches connection config errors', async() => { const sql = postgres({ ...options, user: { toString: () => { throw new Error('wat') } }, database: 'prut' }) diff --git a/src/connection.js b/src/connection.js index 7f8ac5ea..578a6a02 100644 --- a/src/connection.js +++ b/src/connection.js @@ -788,7 +788,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose const error = Errors.postgres(parseError(x)) query && query.retried ? errored(query.retried) - : query && query.prepare && retryRoutines.has(error.routine) + : query && query.prepared && retryRoutines.has(error.routine) ? retry(query, error) : errored(error) } diff --git a/tests/index.js b/tests/index.js index 13734239..dd8d55da 100644 --- a/tests/index.js +++ b/tests/index.js @@ -1789,14 +1789,14 @@ t('Recreate prepared statements on RevalidateCachedQuery error', async() => { ] }) -t('Properly throws routing error on not prepared statements', async() => { +t('Properly throws routine error on not prepared statements', async() => { await sql`create table x (x text[])` const { routine } = await sql.unsafe(`insert into x(x) values (('a', 'b'))`).catch(e => e) return ['transformAssignedExpr', routine, await sql`drop table x`] }) -t('Properly throws routing error on not prepared statements in transaction', async() => { +t('Properly throws routine error on not prepared statements in transaction', async() => { const { routine } = await sql.begin(sql => [ sql`create table x (x text[])`, sql`insert into x(x) values (('a', 'b'))`, @@ -1805,6 +1805,15 @@ t('Properly throws routing error on not prepared statements in transaction', asy return ['transformAssignedExpr', routine] }) +t('Properly throws routine error on not prepared statements using file', async() => { + const { routine } = await sql.unsafe(` + create table x (x text[]); + insert into x(x) values (('a', 'b')); + `, { prepare: true }).catch(e => e) + + return ['transformAssignedExpr', routine] +}) + t('Catches connection config errors', async() => { const sql = postgres({ ...options, user: { toString: () => { throw new Error('wat') } }, database: 'prut' })