import type { DatabaseAdapter, DatabaseResult, ColumnInfo, FieldDefinition } from "../types.js"; export interface PostgresConfig { host?: string; port?: number; user?: string; password?: string; database?: string; connectionString?: string; } export declare class PostgresAdapter implements DatabaseAdapter { private config; /** * Postgres, MySQL and MSSQL all REQUIRE a name for a derived table, so * the COUNT probe in Database.countProbe wraps as * `FROM (sql) AS _count_query`. SQLite and Firebird leave this unset and * get no alias - Firebird rejects `AS` in that position. */ readonly countSubqueryAlias = "_count_query"; private client; private _lastInsertId; private _inTransaction; constructor(config: PostgresConfig | string); /** Connect to PostgreSQL. Must be called before using the adapter. */ /** ADR-0044 required adapter capability. */ getDatabaseType(): string; /** ADR-0044: readable/writable native boolean. */ autocommit: boolean; /** * ADR-0044 / DBA-P02: every built-in adapter can guarantee an atomic * multi-row batch by default. A test-only deployment representing one * that cannot sets this false so executeMany rejects BEFORE the first * write rather than risking partial durability. */ supportsAtomicBatch: boolean; connect(): Promise; private ensureConnected; /** Convert ? placeholders to $1, $2, ... for pg. */ /** Ensure bytea columns are Buffer (already the case with pg). No-op guard. */ private decodeBlobs; private convertPlaceholders; /** * Normalise an `id` column value (typed `unknown` because pg row values are * `unknown`) into the shape `_lastInsertId` / `DatabaseResult.lastId` * expect. At runtime PG returns numeric PKs as number/bigint (the int8/numeric * type parsers above coerce them to Number); a numeric string is coerced to a * number so the SERIAL path always returns the integer id. * * A non-numeric string id — the UUID PK case (`id uuid PRIMARY KEY DEFAULT * gen_random_uuid()`) returned via RETURNING — is preserved as-is so the * insert surfaces the actual id instead of null (#256). null/undefined/empty * still become null. */ private normalizeId; execute(sql: string, params?: unknown[]): unknown; executeMany(sql: string, paramsList: unknown[][]): { totalAffected: number; lastId?: number | bigint; }; /** Async executeMany for real usage. */ executeManyAsync(sql: string, paramsList: unknown[][]): Promise<{ totalAffected: number; lastId?: number | bigint; }>; /** Async execute for real usage. */ executeAsync(sql: string, params?: unknown[]): Promise; query>(sql: string, params?: unknown[]): T[]; /** Async query for real usage. */ queryAsync>(sql: string, params?: unknown[]): Promise; fetch>(sql: string, params?: unknown[], limit?: number, skip?: number): T[]; fetchAsync>(sql: string, params?: unknown[], limit?: number, skip?: number): Promise; fetchOne>(sql: string, params?: unknown[]): T | null; fetchOneAsync>(sql: string, params?: unknown[]): Promise; insert(table: string, data: Record | Record[]): DatabaseResult; insertAsync(table: string, data: Record | Record[]): Promise; update(table: string, data: Record, filter: Record, params?: unknown[]): DatabaseResult; updateAsync(table: string, data: Record, filter: Record | string, params?: unknown[]): Promise; delete(table: string, filter: Record, params?: unknown[]): DatabaseResult; deleteAsync(table: string, filter: Record | string, params?: unknown[]): Promise; startTransaction(): void; startTransactionAsync(): Promise; commit(): void; commitAsync(): Promise; rollback(): void; rollbackAsync(): Promise; getTables(): string[]; tablesAsync(): Promise; getColumns(table: string): ColumnInfo[]; columnsAsync(table: string): Promise; lastInsertId(): number | bigint | string | null; close(): void; tableExists(name: string): boolean; tableExistsAsync(name: string): Promise; createTable(name: string, columns: Record): void; createTableAsync(name: string, columns: Record): Promise; /** Translate SQL for PostgreSQL dialect. */ translateSql(sql: string): string; }