import { DatabaseConnection } from '../../driver/database-connection.js'; /** * Config for the PostgreSQL dialect. */ export interface PostgresDialectConfig { /** * A postgres Pool instance or a function that returns one. * * If a function is provided, it's called once when the first query is executed. * * https://node-postgres.com/apis/pool */ pool: PostgresPool | (() => Promise); /** * https://github.com/brianc/node-postgres/tree/master/packages/pg-cursor * ```ts * import Cursor from 'pg-cursor' * // or * import * as Cursor from 'pg-cursor' * * new PostgresDialect({ * cursor: Cursor * }) * ``` */ cursor?: PostgresCursorConstructor; /** * Called once for each created connection. */ onCreateConnection?: (connection: DatabaseConnection) => Promise; } /** * This interface is the subset of pg driver's `Pool` class that * kysely needs. * * We don't use the type from `pg` here to not have a dependency to it. * * https://node-postgres.com/apis/pool */ export interface PostgresPool { connect(): Promise; end(): Promise; } export interface PostgresPoolClient { query(sql: string, parameters: ReadonlyArray): Promise>; query(cursor: PostgresCursor): PostgresCursor; release(): void; } export interface PostgresCursor { read(rowsCount: number): Promise; close(): Promise; } export type PostgresCursorConstructor = new (sql: string, parameters: unknown[]) => PostgresCursor; export interface PostgresQueryResult { command: 'UPDATE' | 'DELETE' | 'INSERT' | 'SELECT' | 'MERGE'; rowCount: number; rows: R[]; } export interface PostgresStream { [Symbol.asyncIterator](): AsyncIterableIterator; }