mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Slightly better types
This commit is contained in:
parent
64a9aa2eb5
commit
0815f05d15
@ -8,7 +8,10 @@ function isPool(clientOrPool: Client | Pool): clientOrPool is Pool {
|
||||
return 'idleCount' in clientOrPool
|
||||
}
|
||||
|
||||
async function transaction<T>(clientOrPool: Client | Pool, cb: (client: Client) => Promise<T>): Promise<T> {
|
||||
async function transaction<T>(
|
||||
clientOrPool: Client | Pool,
|
||||
cb: (client: Client | PoolClient) => Promise<T>
|
||||
): Promise<T> {
|
||||
let client: Client | PoolClient
|
||||
if (isPool(clientOrPool)) {
|
||||
// It's a Pool
|
||||
@ -19,7 +22,7 @@ async function transaction<T>(clientOrPool: Client | Pool, cb: (client: Client)
|
||||
}
|
||||
await client.query('BEGIN')
|
||||
try {
|
||||
const result = await cb(client as Client)
|
||||
const result = await cb(client)
|
||||
await client.query('COMMIT')
|
||||
return result
|
||||
} catch (error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user