Skip to content

Instantly share code, notes, and snippets.

@jgoux
Created April 19, 2019 12:24
Embed
What would you like to do?
async function withAuthenticatedPgClient(
{ pgPool, needTransaction, sqlSettingsQuery },
fn
) {
const provideClient = async pgClient => {
if (sqlSettingsQuery) {
await pgClient.query(sqlSettingsQuery)
}
return await fn(pgClient)
}
return pgPool.task(pgClient =>
needTransaction ? pgClient.tx(provideClient) : provideClient(pgClient)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment