| 121 | * MySQL Connector Implementation |
| 122 | */ |
| 123 | export class MySQLConnector implements Connector { |
| 124 | id: ConnectorType = "mysql"; |
| 125 | name = "MySQL"; |
| 126 | dsnParser = new MySQLDSNParser(); |
| 127 | |
| 128 | private pool: mysql.Pool | null = null; |
| 129 | // Source ID is set by ConnectorManager after cloning |
| 130 | private sourceId: string = "default"; |
| 131 | private queryTimeoutMs?: number; |
| 132 | |
| 133 | getId(): string { |
| 134 | return this.sourceId; |
| 135 | } |
| 136 | |
| 137 | clone(): Connector { |
| 138 | return new MySQLConnector(); |
| 139 | } |
| 140 | |
| 141 | async connect(dsn: string, initScript?: string, config?: ConnectorConfig): Promise<void> { |
| 142 | try { |
| 143 | const connectionOptions = await this.dsnParser.parse(dsn, config); |
| 144 | this.pool = mysql.createPool(connectionOptions); |
| 145 | |
| 146 | // Store query timeout for per-query application |
| 147 | if (config?.queryTimeoutSeconds !== undefined) { |
| 148 | this.queryTimeoutMs = config.queryTimeoutSeconds * 1000; |
| 149 | } |
| 150 | |
| 151 | // Test the connection |
| 152 | const [rows] = await this.pool.query("SELECT 1"); |
| 153 | } catch (err) { |
| 154 | console.error("Failed to connect to MySQL database:", err); |
| 155 | throw err; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | async disconnect(): Promise<void> { |
| 160 | if (this.pool) { |
| 161 | await this.pool.end(); |
| 162 | this.pool = null; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | async getSchemas(): Promise<string[]> { |
| 167 | if (!this.pool) { |
| 168 | throw new Error("Not connected to database"); |
| 169 | } |
| 170 | |
| 171 | try { |
| 172 | // In MySQL, schemas are equivalent to databases. Exclude server-level |
| 173 | // system databases so the list matches the user-facing schemas only |
| 174 | // (parity with the PostgreSQL connector, which hides pg_catalog et al.). |
| 175 | const [rows] = (await this.pool.query(` |
| 176 | SELECT SCHEMA_NAME |
| 177 | FROM INFORMATION_SCHEMA.SCHEMATA |
| 178 | WHERE SCHEMA_NAME NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys') |
| 179 | ORDER BY SCHEMA_NAME |
| 180 | `)) as [any[], any]; |
nothing calls this directly
no outgoing calls
no test coverage detected