@@ -235,7 +235,7 @@ function Postgres(a, b) {
235
235
const queries = Queue ( )
236
236
let savepoints = 0
237
237
, connection
238
- let transactionId = null
238
+ , prepare = null
239
239
240
240
try {
241
241
await sql . unsafe ( 'begin ' + options . replace ( / [ ^ a - z ] / ig, '' ) , [ ] , { onexecute } ) . execute ( )
@@ -247,7 +247,7 @@ function Postgres(a, b) {
247
247
async function scope ( c , fn , name ) {
248
248
const sql = Sql ( handler )
249
249
sql . savepoint = savepoint
250
- sql . prepare = prepare
250
+ sql . prepare = x => prepare = x . replace ( / [ ^ a - z 0 - 9 $ - _ . ] / gi )
251
251
let uncaughtError
252
252
, result
253
253
@@ -268,11 +268,12 @@ function Postgres(a, b) {
268
268
throw e instanceof PostgresError && e . code === '25P02' && uncaughtError || e
269
269
}
270
270
271
- if ( transactionId ) {
272
- ! name && await sql . unsafe ( ` prepare transaction ' ${ transactionId } '` )
273
- } else {
274
- ! name && await sql `commit`
271
+ if ( ! name ) {
272
+ prepare
273
+ ? await sql `prepare transaction ' ${ sql . unsafe ( prepare ) } '`
274
+ : await sql `commit`
275
275
}
276
+
276
277
return result
277
278
278
279
function savepoint ( name , fn ) {
@@ -291,9 +292,6 @@ function Postgres(a, b) {
291
292
}
292
293
}
293
294
294
- async function prepare ( name ) {
295
- transactionId = name
296
- }
297
295
function onexecute ( c ) {
298
296
connection = c
299
297
move ( c , reserved )
@@ -303,7 +301,6 @@ function Postgres(a, b) {
303
301
}
304
302
}
305
303
306
-
307
304
function move ( c , queue ) {
308
305
c . queue . remove ( c )
309
306
queue . push ( c )
@@ -468,7 +465,7 @@ function parseOptions(a, b) {
468
465
...Object . entries ( defaults ) . reduce (
469
466
( acc , [ k , d ] ) => {
470
467
const value = k in o ? o [ k ] : k in query
471
- ? ( query [ k ] === 'disable' || query [ k ] === 'false' ? false : query [ k ] )
468
+ ? ( query [ k ] === 'disable' || query [ k ] === 'false' ? false : query [ k ] )
472
469
: env [ 'PG' + k . toUpperCase ( ) ] || d
473
470
acc [ k ] = typeof value === 'string' && ints . includes ( k )
474
471
? + value
0 commit comments