Skip to content

Commit 75914c7

Browse files
committed
Fix fragments in transactions - fixes porsager#333
1 parent f1e41c3 commit 75914c7

File tree

6 files changed

+36
-21
lines changed

6 files changed

+36
-21
lines changed

cjs/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function Postgres(a, b) {
207207
}
208208

209209
async function scope(c, fn, name) {
210-
const sql = Sql(handler, true)
210+
const sql = Sql(handler)
211211
sql.savepoint = savepoint
212212
let uncaughtError
213213
name && await sql`savepoint ${ sql(name) }`

cjs/tests/index.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,24 @@ t('Transaction requests are executed implicitly', async() => {
237237
const sql = postgres({ debug: true, idle_timeout: 1, fetch_types: false })
238238
return [
239239
'testing',
240-
(await sql.begin(async sql => {
241-
sql`select set_config('postgres_js.test', 'testing', true)`
242-
return await sql`select current_setting('postgres_js.test') as x`
243-
}))[0].x
240+
(await sql.begin(sql => [
241+
sql`select set_config('postgres_js.test', 'testing', true)`,
242+
sql`select current_setting('postgres_js.test') as x`
243+
]))[1][0].x
244244
]
245245
})
246246

247247
t('Uncaught transaction request errors bubbles to transaction', async() => [
248248
'42703',
249-
(await sql.begin(sql => (
249+
(await sql.begin(sql => [
250250
sql`select wat`,
251251
sql`select current_setting('postgres_js.test') as x, ${ 1 } as a`
252-
)).catch(e => e.code))
252+
]).catch(e => e.code))
253+
])
254+
255+
t('Fragments in transactions', async() => [
256+
true,
257+
(await sql.begin(sql => sql`select true as x where ${ sql`1=1` }`))[0].x
253258
])
254259

255260
t('Transaction rejects with rethrown error', async() => [

deno/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ function Postgres(a, b) {
208208
}
209209

210210
async function scope(c, fn, name) {
211-
const sql = Sql(handler, true)
211+
const sql = Sql(handler)
212212
sql.savepoint = savepoint
213213
let uncaughtError
214214
name && await sql`savepoint ${ sql(name) }`

deno/tests/index.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,24 @@ t('Transaction requests are executed implicitly', async() => {
239239
const sql = postgres({ debug: true, idle_timeout: 1, fetch_types: false })
240240
return [
241241
'testing',
242-
(await sql.begin(async sql => {
243-
sql`select set_config('postgres_js.test', 'testing', true)`
244-
return await sql`select current_setting('postgres_js.test') as x`
245-
}))[0].x
242+
(await sql.begin(sql => [
243+
sql`select set_config('postgres_js.test', 'testing', true)`,
244+
sql`select current_setting('postgres_js.test') as x`
245+
]))[1][0].x
246246
]
247247
})
248248

249249
t('Uncaught transaction request errors bubbles to transaction', async() => [
250250
'42703',
251-
(await sql.begin(sql => (
251+
(await sql.begin(sql => [
252252
sql`select wat`,
253253
sql`select current_setting('postgres_js.test') as x, ${ 1 } as a`
254-
)).catch(e => e.code))
254+
]).catch(e => e.code))
255+
])
256+
257+
t('Fragments in transactions', async() => [
258+
true,
259+
(await sql.begin(sql => sql`select true as x where ${ sql`1=1` }`))[0].x
255260
])
256261

257262
t('Transaction rejects with rethrown error', async() => [

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function Postgres(a, b) {
207207
}
208208

209209
async function scope(c, fn, name) {
210-
const sql = Sql(handler, true)
210+
const sql = Sql(handler)
211211
sql.savepoint = savepoint
212212
let uncaughtError
213213
name && await sql`savepoint ${ sql(name) }`

tests/index.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,24 @@ t('Transaction requests are executed implicitly', async() => {
237237
const sql = postgres({ debug: true, idle_timeout: 1, fetch_types: false })
238238
return [
239239
'testing',
240-
(await sql.begin(async sql => {
241-
sql`select set_config('postgres_js.test', 'testing', true)`
242-
return await sql`select current_setting('postgres_js.test') as x`
243-
}))[0].x
240+
(await sql.begin(sql => [
241+
sql`select set_config('postgres_js.test', 'testing', true)`,
242+
sql`select current_setting('postgres_js.test') as x`
243+
]))[1][0].x
244244
]
245245
})
246246

247247
t('Uncaught transaction request errors bubbles to transaction', async() => [
248248
'42703',
249-
(await sql.begin(sql => (
249+
(await sql.begin(sql => [
250250
sql`select wat`,
251251
sql`select current_setting('postgres_js.test') as x, ${ 1 } as a`
252-
)).catch(e => e.code))
252+
]).catch(e => e.code))
253+
])
254+
255+
t('Fragments in transactions', async() => [
256+
true,
257+
(await sql.begin(sql => sql`select true as x where ${ sql`1=1` }`))[0].x
253258
])
254259

255260
t('Transaction rejects with rethrown error', async() => [

0 commit comments

Comments
 (0)