Skip to content

Commit fb73e93

Browse files
committed
Please the linter
1 parent 8f6f4e3 commit fb73e93

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/index.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ function Postgres(a, b) {
235235
const queries = Queue()
236236
let savepoints = 0
237237
, connection
238-
let transactionId = null
238+
, prepare = null
239239

240240
try {
241241
await sql.unsafe('begin ' + options.replace(/[^a-z ]/ig, ''), [], { onexecute }).execute()
@@ -247,7 +247,7 @@ function Postgres(a, b) {
247247
async function scope(c, fn, name) {
248248
const sql = Sql(handler)
249249
sql.savepoint = savepoint
250-
sql.prepare = prepare
250+
sql.prepare = x => prepare = x.replace(/[^a-z0-9$-_. ]/gi)
251251
let uncaughtError
252252
, result
253253

@@ -268,11 +268,12 @@ function Postgres(a, b) {
268268
throw e instanceof PostgresError && e.code === '25P02' && uncaughtError || e
269269
}
270270

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`
275275
}
276+
276277
return result
277278

278279
function savepoint(name, fn) {
@@ -291,9 +292,6 @@ function Postgres(a, b) {
291292
}
292293
}
293294

294-
async function prepare(name) {
295-
transactionId = name
296-
}
297295
function onexecute(c) {
298296
connection = c
299297
move(c, reserved)
@@ -303,7 +301,6 @@ function Postgres(a, b) {
303301
}
304302
}
305303

306-
307304
function move(c, queue) {
308305
c.queue.remove(c)
309306
queue.push(c)
@@ -468,7 +465,7 @@ function parseOptions(a, b) {
468465
...Object.entries(defaults).reduce(
469466
(acc, [k, d]) => {
470467
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])
472469
: env['PG' + k.toUpperCase()] || d
473470
acc[k] = typeof value === 'string' && ints.includes(k)
474471
? +value

tests/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ t('Prepared transaction', async() => {
246246
await sql.prepare('tx1')
247247
})
248248

249-
await sql.unsafe("commit prepared 'tx1'")
249+
await sql`commit prepared 'tx1'`
250250

251251
return ['1', (await sql`select count(1) from test`)[0].count, await sql`drop table test`]
252252
})

0 commit comments

Comments
 (0)