Skip to content

Commit

Permalink
Properly check if prepared
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Mar 20, 2024
1 parent 6f20f3f commit f82ca1b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cjs/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 11 additions & 2 deletions cjs/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))`,
Expand All @@ -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' })

Expand Down
2 changes: 1 addition & 1 deletion deno/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 11 additions & 2 deletions deno/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))`,
Expand All @@ -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' })

Expand Down
2 changes: 1 addition & 1 deletion src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 11 additions & 2 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))`,
Expand All @@ -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' })

Expand Down

0 comments on commit f82ca1b

Please sign in to comment.