import type { DatabaseSchema } from '../schema/types'; export interface PoolOptions { /** Maximum number of clients in the pool. */ max?: number; /** Milliseconds an idle client may live before being closed. */ idleTimeoutMillis?: number; /** Milliseconds to wait for a new client connection before failing. */ connectionTimeoutMillis?: number; } export interface ConnectionConfig { host?: string; port?: number; user?: string; password?: string; database: string; schema?: string; /** Driver-specific connection-pool tuning. Forwarded to `new pg.Pool()` for the postgres driver. */ pool?: PoolOptions; /** * How filter keys passed to `find()` / `count()` are interpreted: * - `'snake'` (default): keys must match the column names exactly. * - `'camel'`: camelCase keys are translated to snake_case before SQL. * * Independent of how mtbREST treats wire-format casing — the ORM-level * setting only affects the Filter API. */ caseConvention?: 'snake' | 'camel'; [key: string]: unknown; } export interface QueryResult { rows: Record[]; rowCount: number; } export interface ExecuteResult { rowCount: number; insertId?: unknown; } export interface Dialect { /** Quote an identifier (table/column). */ quoteIdent(name: string): string; /** Render the Nth (1-based) parameter placeholder. */ placeholder(n: number): string; /** Whether INSERT ... RETURNING is supported. If not, drivers must populate insertId on ExecuteResult. */ supportsReturning: boolean; /** Default schema name when none is configured. */ defaultSchema: string; } /** Returned from Driver.listen — call to detach the handler and (if last) UNLISTEN. */ export type Unlisten = () => Promise; export interface Driver { readonly dialect: Dialect; connect(config: ConnectionConfig): Promise; query(sql: string, params?: unknown[]): Promise; execute(sql: string, params?: unknown[]): Promise; introspect(schema?: string): Promise; close(): Promise; /** Wrap callback in a transaction. */ transaction(fn: () => Promise): Promise; /** * Subscribe to a Postgres-style asynchronous notification channel * (`LISTEN` / `pg_notify`). Drivers that don't support it should leave * this undefined; consumers should feature-detect. */ listen?(channel: string, handler: (payload: string) => void): Promise; }