PostgresService manages a connection to a postgres database using pools and creates PostgresClient objects from the pool to talk query the database.

const env = {
DATABASE_URL: 'postgres://user:secret@127.0.0.1/database',
}

const postgres = new PostgresService(env)

Hierarchy

  • PostgresService

Constructors

Methods

Constructors

Methods

  • checkHealth assert that the database is still connected, or reject with an error.

    Returns Promise<void>

  • run is a utility for quickly getting a client, running a query and releasing the client. It accepts a previousClient to be reused instead of creating another. Whatever is returned from your code is resolved into the promise.

    const result = await postgres.run((client) => {
    await client.sql`SELECT 1;`
    return 'ok'
    })

    12/11/21 - Upon writing these docs previousClient seems a bit pointless, if you already have a client, why call this function?

    Type Parameters

    • T

    Parameters

    Returns Promise<T>

Generated using TypeDoc