Interface Client

A database client, encapsulating a single connection to the database.

interface Client {
    closed: boolean;
    config: Configuration;
    encrypted: boolean;
    parameters: ReadonlyMap<string, string>;
    processId: null | number;
    secretKey: null | number;
    transactionStatus: null | TransactionStatus;
    [asyncDispose](): Promise<void>;
    end(): Promise<void>;
    off<K>(event, listener): void;
    on<K>(event, listener): void;
    prepare<T>(text): Promise<PreparedStatement<T>>;
    query<T>(text, values?): ResultIterator<T>;
}

Properties

closed: boolean = true
config: Configuration = {}

An optional configuration object, comprised of connection details and client configuration. Most of the connection details can also be specified using environment variables, see Environment.

encrypted: boolean
parameters: ReadonlyMap<string, string>
processId: null | number = null
secretKey: null | number = null
transactionStatus: null | TransactionStatus = null

Methods

  • End the database connection.

    Returns Promise<void>

  • Type Parameters

    • K extends "error" | "notice" | "notification"

    Parameters

    Returns void

  • Type Parameters

    • K extends "error" | "notice" | "notification"

    Parameters

    Returns void

  • Send a query to the database.

    The query string is given as the first argument, or pass a Query object which provides more control.

    Type Parameters

    Parameters

    • text: string | Query

      The query string, or pass a Query object which provides more control (including streaming values into a socket).

    • Optional values: any[]

      The query parameters, corresponding to $1, $2, etc.

    Returns ResultIterator<T>

    A promise for the query results.