Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @ovotech/laminar-pg

Index

Classes Other

Classes pg

Interfaces

Type aliases

Functions

Type aliases

PgContext<TConfig>: Record<keyof TConfig, PgClient>

Context with one or more database clients connected.

By default client is db.

You can define multiple client by using an object with PgService properties.

type MyDatabasesContext = PgContext<{ db1: PgService, db2: PgService }>;

Type parameters

PgMiddlewareConfig: Record<string, PgService>

Functions

  • A middleware that handles DB access. Each request gets its own pool client, so there is isolation between requests and their transactions.

    We are also able to handle exceptions gracefully, releasing the client from the pool in an event of one.

    Can be used with any resolver function, like http listener or queue worker.

    Supports multiple pools, and would create connections to all of them simultaneously.

    const pool = new Pool({ connectionString: '...' });
    const pg = new PgService(pool);

    const withDb = pgMiddleware(pg);

    new HttpService({ listener: withDb(async ({ db }) => {
    * console.log(await db.query('...'));
    }) });

    // Multiple
    // ----------------
    const pg1 = new PgService(new Pool({ connectionString: '...' }));
    const pg2 = new PgService(new Pool({ connectionString: '...' }));

    const withDbs = pgMiddleware({ db1: pg1, db2: pg2 });

    new HttpService({ listener: withDb(async ({ db1, db2 }) => {
    console.log(await db1.query('...'));
    console.log(await db2.query('...'));
    }) });

    Parameters

    Returns Middleware<PgContext>

  • Type parameters

    Parameters

    • config: TConfig

    Returns Middleware<PgContext<TConfig>>

Generated using TypeDoc