UNPKG

@200systems/mf-db-mysql

Version:

MySQL database client with connection pooling, migrations, and health monitoring

59 lines 2.09 kB
import { QueryError, TransactionError, BaseTransaction } from '@200systems/mf-db-core'; /** * MySQL Transaction implementation using the unified BaseTransaction */ export class MySQLTransaction extends BaseTransaction { connection; constructor(connection, logger) { super(logger, 'mysql'); // Pass database type to base class this.connection = connection; } async query(text, params = []) { if (this.completed) { throw new TransactionError('Transaction has already been completed'); } try { this.logger.debug('Executing MySQL transaction query', { query: text, params, dbType: this.dbType }); const startTime = Date.now(); const [rows, fields] = await this.connection.execute(text, params); const duration = Date.now() - startTime; this.logger.debug('MySQL transaction query executed', { duration, dbType: this.dbType }); return { rows: rows, rowCount: Array.isArray(rows) ? rows.length : rows.affectedRows || 0, fields: fields?.map(field => ({ name: field.name, dataTypeID: field.type, })), }; } catch (error) { this.logger.error('MySQL transaction query failed', error instanceof Error ? error : new Error(String(error)), { error, query: text, params, dbType: this.dbType }); throw new QueryError(`MySQL transaction query failed: ${error.message}`, text, params, error); } } async doCommit() { await this.connection.commit(); await this.ensureCleanup(); } async doRollback() { await this.connection.rollback(); await this.ensureCleanup(); } async doCleanup() { this.connection.release(); } } //# sourceMappingURL=transaction.js.map