/** * PostgreSQL 数据库适配器 * 使用 pg 驱动实现 DbAdapter 接口 * * 性能优化:使用批量查询获取 Schema 信息,避免 N+1 查询问题 * 连接管理:使用连接池 + TCP Keep-Alive + 断线自动重试,确保长连接稳定性 */ import type { DbAdapter, QueryResult, SchemaInfo } from '../types/adapter.js'; export declare class PostgreSQLAdapter implements DbAdapter { private pool; private config; constructor(config: { host: string; port: number; user?: string; password?: string; database?: string; }); /** * 检测是否为连接断开类错误 */ private isConnectionError; /** * 带断线重试的操作包装器(连接池会自动提供新连接) */ private withRetry; /** * 连接到 PostgreSQL 数据库 */ connect(): Promise; /** * 断开数据库连接 */ disconnect(): Promise; /** * 执行 SQL 查询 */ executeQuery(query: string, params?: unknown[]): Promise; /** * 获取数据库结构信息(批量查询优化版本) * * 优化前:每个表需要 4 次查询(列、主键、索引、行数) * 优化后:只需要 4 次查询获取所有表的信息 */ getSchema(): Promise; /** * getSchema 内部实现 */ private _getSchemaImpl; /** * 构建带 schema 前缀的表名键 * 默认 schema (public) 的表直接用表名,保持向后兼容 */ private makeTableKey; /** * 组装 Schema 信息 */ private assembleSchema; /** * 检查是否为写操作 */ isWriteOperation(query: string): boolean; } //# sourceMappingURL=postgres.d.ts.map