import type { Pool, PoolClient, QueryResult } from 'pg'; import type { SchemaSnapshot, SchemaSnapshotHost } from './db/schema-snapshot.js'; export type { Pool, PoolClient, QueryResult } from 'pg'; /** * Values array for parameterized queries. */ export type QueryValues = unknown[]; /** * Common interface for database clients. * PoolAdapter implements this interface by wrapping a pg.Pool. */ export interface DbClient { /** * The underlying connection pool. */ readonly $pool: Pool; /** * Acquire a client from the pool for manual query execution. * Remember to call client.release() when done. */ connect(): Promise; /** * Execute a query that returns no data. * Use for INSERT, UPDATE, DELETE without RETURNING. */ none(query: string, values?: QueryValues): Promise; /** * Execute a query that returns exactly one row. * @throws Error if zero or more than one row is returned */ one(query: string, values?: QueryValues): Promise; /** * Execute a query that returns zero or one row. * @returns The row, or null if no rows returned * @throws Error if more than one row is returned */ oneOrNone(query: string, values?: QueryValues): Promise; /** * Execute a query that returns any number of rows (including zero). * Alias for manyOrNone. */ any(query: string, values?: QueryValues): Promise; /** * Execute a query that returns zero or more rows. */ manyOrNone(query: string, values?: QueryValues): Promise; /** * Execute a query that returns at least one row. * @throws Error if no rows are returned */ many(query: string, values?: QueryValues): Promise; /** * Execute a raw query, returning the full result object. */ query(query: string, values?: QueryValues): Promise; /** * Execute a function within a transaction. * Automatically handles BEGIN, COMMIT, and ROLLBACK. */ tx(callback: (t: TxClient) => Promise): Promise; } /** * Transaction client interface for executing queries within a transaction. */ export interface TxClient { none(query: string, values?: QueryValues): Promise; one(query: string, values?: QueryValues): Promise; oneOrNone(query: string, values?: QueryValues): Promise; any(query: string, values?: QueryValues): Promise; manyOrNone(query: string, values?: QueryValues): Promise; many(query: string, values?: QueryValues): Promise; query(query: string, values?: QueryValues): Promise; /** * Await multiple query promises. Prefer collecting results from * TransactionClient methods (which serialize onto one PoolClient); * do not start raw `client.query` calls concurrently. */ batch(promises: Promise[]): Promise; } /** * Adapter that wraps a pg.Pool to implement DbClient. */ export declare class PoolAdapter implements DbClient { readonly $pool: Pool; constructor($pool: Pool); connect(): Promise; none(query: string, values?: QueryValues): Promise; one(query: string, values?: QueryValues): Promise; oneOrNone(query: string, values?: QueryValues): Promise; any(query: string, values?: QueryValues): Promise; manyOrNone(query: string, values?: QueryValues): Promise; many(query: string, values?: QueryValues): Promise; query(query: string, values?: QueryValues): Promise; tx(callback: (t: TxClient) => Promise): Promise; } /** * DbClient adapter that pins all queries to a single PoolClient. * * Used during PostgresStore.init() to funnel every domain's DDL through * one backend connection. This collapses ~200 per-statement pool checkouts * into a single connection acquisition, which: * - removes connection-handshake RTT on remote/managed Postgres * - makes the entire init look like one transaction to a transaction * pooler (PgBouncer/Supabase), avoiding pooler-budget exhaustion * - eliminates inter-statement lock contention by construction (a single * backend serializes statements naturally) * * The wrapped client is the caller's responsibility to release. */ export declare class PinnedClientAdapter implements DbClient { #private; readonly $pool: Pool; private readonly pinnedClient; constructor($pool: Pool, pinnedClient: PoolClient); connect(): Promise; none(query: string, values?: QueryValues): Promise; one(query: string, values?: QueryValues): Promise; oneOrNone(query: string, values?: QueryValues): Promise; any(query: string, values?: QueryValues): Promise; manyOrNone(query: string, values?: QueryValues): Promise; many(query: string, values?: QueryValues): Promise; query(query: string, values?: QueryValues): Promise; tx(callback: (t: TxClient) => Promise): Promise; } /** * DbClient wrapper that routes to an alternate client when one is pinned. * * Most of the time this just forwards to the underlying PoolAdapter. * During PostgresStore.init() we temporarily pin a single-client adapter * so every domain's DDL flows through one backend connection. */ export declare class RoutingDbClient implements DbClient, SchemaSnapshotHost { #private; constructor(base: DbClient); /** * Catalog snapshot for the current init window, or `null` outside it. * * It lives here rather than on `PgDB` because every storage domain builds its * own `PgDB` over this one shared client — hanging the snapshot off the * client means one load serves all of them, and its lifetime lines up exactly * with the pinned-init window that `pin()`/`unpin()` already delimit. */ get schemaSnapshot(): SchemaSnapshot | null; /** Install (or clear, with `null`) the init-window catalog snapshot. */ setSchemaSnapshot(snapshot: SchemaSnapshot | null): void; /** Returns the currently active client (pinned if set, otherwise base). */ private get active(); /** * Pin a DbClient so all subsequent calls route through it until unpinned. * Throws if a client is already pinned to avoid silent overrides. */ pin(client: DbClient): void; unpin(): void; get $pool(): Pool; connect(): Promise; none(query: string, values?: QueryValues): Promise; one(query: string, values?: QueryValues): Promise; oneOrNone(query: string, values?: QueryValues): Promise; any(query: string, values?: QueryValues): Promise; manyOrNone(query: string, values?: QueryValues): Promise; many(query: string, values?: QueryValues): Promise; query(query: string, values?: QueryValues): Promise; tx(callback: (t: TxClient) => Promise): Promise; } //# sourceMappingURL=client.d.ts.map