/** One statement of a batch; `values` travel as bind parameters (text, or null), never in the SQL text. */ export type Statement = { text: string; values?: ReadonlyArray; }; /** What one statement answered: its columns and rows in Postgres's text format, and its command tag. */ export type StatementResult = { fields: string[]; rows: Array>; command: string; }; /** A Postgres error as the backend reported it (SQLSTATE and its fields), what a vendor's server passes through. */ export declare class EngineDatabaseError extends Error { readonly code: string; readonly detail: string | null; readonly hint: string | null; constructor(message: string, fields: { code?: string; detail?: string; hint?: string; }); } /** The World's database cannot be reached: none is bound, or it does not answer. */ export declare class EngineUnavailableError extends Error { constructor(message: string); } /** One transaction: as `role` (none: the twin's own login role, the vendor's servers' own work), with transaction-local * `settings` (`request.jwt.claims`, `search_path`), READ ONLY when `readOnly` (a write is refused by Postgres itself, * 25006), ended with ROLLBACK when `rollback` (a permission probe asked of Postgres and undone). */ export type Batch = { role?: string; settings?: Record; readOnly?: boolean; rollback?: boolean; statements: Statement[]; }; export interface ManagedDatabase { /** Whether the World binds a database at all (a World with none refuses every batch). */ readonly bound: boolean; /** The URL the World binds it at, what an application connects to (a credential door's database URL); none when * unbound. */ readonly url?: string; /** One transaction as one pipeline and one Sync; the answer is the batch's own statements', in order. */ batch(batch: Batch): Promise; /** A whole SQL script as one simple Query (a vendor's migrations, several statements to a file). */ script(text: string): Promise; } /** Quote an identifier the way Postgres's quote_ident does for a name that needs it. */ export declare function quoteIdent(name: string): string; /** The part of a Postgres driver the kernel uses: node-postgres's (`pg`) Pool and its clients. */ type PgClient = { query(query: unknown): unknown; release(error?: Error): void; }; type PgPool = { connect(): Promise; end(): Promise; on(event: 'error', listener: (error: Error) => void): unknown; }; export type DatabaseDriver = { Pool: new (config: { connectionString: string; max: number; idleTimeoutMillis: number; connectionTimeoutMillis: number; }) => PgPool; }; /** A Postgres driver a host registers in place of node-postgres. */ export declare function useDatabaseDriver(given: DatabaseDriver): void; /** The World's Postgres at `url` (the runtime's binding, never the environment); with `readOnly`, every transaction is * READ ONLY whatever the batch asks (a read-only twin or request: Postgres itself refuses a write, 25006). */ export declare function managedDatabase(url: string, options?: { readOnly?: boolean; }): ManagedDatabase; /** One connection of an application's own to the World's Postgres (a journey's SQL steps: twin-standard * walk/journey-kit.ts), its statements sent as its client sends them: a text alone as one simple Query (a migration * file, a `BEGIN`), a text with values as one extended-protocol statement, the values bind parameters. A transaction it * opens stays open across its statements until it ends it, as on the application's own connection. Each statement's * answer is its results in Postgres's text format, with native column type OIDs retained beside the values. */ export type DatabaseSession = { query(text: string, values?: ReadonlyArray): Promise>; end(): Promise; }; /** The World's Postgres at `url` as one connection held until `end()`. */ export declare function databaseSession(url: string): Promise; /** A handler's database when the World binds none: every use is the refusal naming what to add. */ export declare function unboundDatabase(service: string): ManagedDatabase; export {};