Skip to content

Instantly share code, notes, and snippets.

@jgoux
Created April 19, 2019 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgoux/f26062a635f2275c9742c6d1442c9fa3 to your computer and use it in GitHub Desktop.
Save jgoux/f26062a635f2275c9742c6d1442c9fa3 to your computer and use it in GitHub Desktop.
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