UNPKG

@kwaeri/postgresql-database-driver

Version:

The @kwaeri/postgresql-database-driver component of the @kwaer/node-kit application platform.

69 lines (68 loc) 2.72 kB
/** * SPDX-PackageName: kwaeri/postgresql-database-driver * SPDX-PackageVersion: 0.5.0 * SPDX-FileCopyrightText: © 2014 - 2022 Richard Winters <kirvedx@gmail.com> and contributors * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR MIT */ import Postgres from 'pg'; import { DatabaseDriver, DriverConnectionBits, QueryResult } from '@kwaeri/database-driver'; /** * The PostgreSQLDriver implements the PostgreSQL database provider */ export declare class PostgreSQLDriver extends DatabaseDriver { /** * @var { Postgres./Pool } pool */ pool: Postgres.Pool; /** * Class constructor */ constructor(config: DriverConnectionBits); /** * Executes a transaction [checkout, use, return] query on a pooled client, using the postgres * database driver. * * @param { string } query The query string to be executed, with optional placeholders (i.e. $1, $2, $3 ... ) * @param { any[] } bits An array of parameter placeholders (i.e. [1, "Richard"].) * * @return { Promise<QueryResult> } A promise for a {@link QueryResult} object. * * **Example**: * * ```typescript * const { rows, fields } = await query( 'select * from people where first_name=$1;', ["Richard"]); * ``` * * Though, if you're not using parameters, the bits argument is entirely optional and can be left out. * * See the [official documentation](https://node-postgres.com/features/pooling) */ clientQuery<T extends QueryResult>(query: string, bits?: any[]): Promise<T>; /** * Executes a standard [the preferred way to] query on any available client in the pool, using the postgres * database driver. * * @param { string } query The query string to be executed, with optional placeholders (i.e. $1, $2, $3 ... ) * @param { any[] } bits An array of parameter placeholders (i.e. [1, "Richard"].) * * @return { Promise<QueryResult> } A promise for a {@link QueryResult} object. * * **Example**: * * ```typescript * const { rows, fields } = await query( 'select * from people where first_name=$1;', ["Richard"]); * ``` * * Though, if you're not using parameters, the bits argument is entirely optional and can be left out. * * See the [official documentation](https://node-postgres.com/features/pooling) */ query<T extends QueryResult>(query: string, bits?: any[]): Promise<T>; /** * When using the PostgreSQL database driver, one should call end on the connection pool * after the pool has been used. * * @returns { undefined } `undefined` on success */ destroyPool(): Promise<undefined>; }