/** * MySQL 数据库适配器 * 使用 mysql2 驱动实现 DbAdapter 接口 * * 性能优化:使用批量查询获取 Schema 信息,避免 N+1 查询问题 * 连接管理:使用连接池 + TCP Keep-Alive + 断线自动重试,确保长连接稳定性 */ import type { QueryResult, SchemaInfo } from '../types/adapter.js'; import { BaseAdapter, BatchResult, ExecuteBatchOptions, ExecuteScriptOptions, TransactionContext } from './base.js'; export declare class MySQLAdapter extends BaseAdapter { private pool; private config; constructor(config: { host: string; port: number; user?: string; password?: string; database?: string; poolConfig?: { max?: number; min?: number; idleTimeoutMs?: number; }; }); /** * 连接到 MySQL 数据库 */ connect(): Promise; /** * 断开数据库连接 */ disconnect(): Promise; /** * 执行 SQL 查询 */ executeQuery(query: string, params?: unknown[]): Promise; /** * 获取数据库结构信息(批量查询优化版本) * * 优化前:每个表需要 4 次查询(列、主键、索引、行数) * 优化后:只需要 4 次查询获取所有表的信息 */ getSchema(): Promise; /** * getSchema 内部实现 */ private _getSchemaImpl; /** * 组装 Schema 信息 */ private assembleSchema; /** * 检查是否为写操作 */ isWriteOperation(query: string): boolean; /** * Override getDialect for sql-parser compatibility */ protected getDialect(): import('../utils/adapter-factory.js').DbType; /** * Override executeBatch with per-row execution (loop over paramsList). * v3.2.8 Bug #30 + #32 fix: mysql2's `pool.query(sql, [nestedArray])` only works for `VALUES ?` * syntax (single placeholder). For our generic `VALUES (?, ?)` shape we must loop row-by-row. * We use a single physical connection from the pool to keep atomic semantics when useTransaction=true. */ executeBatch(sql: string, paramsList: unknown[][], options?: ExecuteBatchOptions): Promise; /** * P0-3: Override withTransaction to use a single physical connection from the pool. * All statements inside the callback's `tx.executeQuery` are guaranteed to run on * the same connection, so BEGIN/COMMIT/ROLLBACK provide true all-or-nothing semantics. */ withTransaction(fn: (tx: TransactionContext) => Promise): Promise; /** * P0-3: Override executeScript to use withTransaction. * All statements run on a single connection so BEGIN/COMMIT are atomic. * Non-transactional mode falls back to the BaseAdapter default. */ executeScript(query: string, options?: ExecuteScriptOptions): Promise; } //# sourceMappingURL=mysql.d.ts.map