@bamsfaas/pg-connection-wrapper
v1.0.0
Published
``` const {useClient} = require('pg-connection-wrapper')
Downloads
3
Readme
Usage
const {useClient} = require('pg-connection-wrapper')
const dbConfig = // Get database config such as access credentials
async function accessDatabase() {
const result = await useClient(dbConfig, client => {
// Access database via client
return ...
})
// Use result
}
Replaces
const dbConfig = // Get database config such as access credentials
async function accessDatabase() {
const client = new Client(dbConfig)
await client.connect()
try {
// Access database via client
const result = ...
// Use result
} finally {
client.end()
}
}
Look up documentation of 'pg' npm package to see details about database config and client objects.