How to use the pg.connectAsync function in pg

To help you get started, we’ve selected a few pg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graphile / postgraphile / src / createServer.js View on Github external
server.all(route, graphqlHTTP(async (req, res) => {
    // Acquire a new client for every request.
    const client = await pg.connectAsync(pgConfig)

    try {
      // Start a transaction for our client and set it up.
      await client.queryAsync('begin')

      // If we have a secret, let’s setup the request transaction.
      await setupRequestTransaction(req, client, secret, anonymousRole)

      // Make sure we release our client back to the pool once the response has
      // finished.
      onFinished(res, () => {
        // Try to end our session with a commit. If it succeeds, release the
        // client back into the pool. If it fails, release the client back into
        // the pool, but also report that it failed. We cannot report an error in
        // the request at this point because it has finished.
        client.queryAsync('commit')
github graphile / postgraphile / src / postgres / getCatalog.js View on Github external
const withClient = fn => async pgConfig => {
  const client = await pg.connectAsync(pgConfig)
  const result = await fn(client)
  client.end()
  return result
}