import mysql from 'mysql2/promise'; export async function createConnection(uri: string) { try { const connection = await mysql.createConnection(uri); return connection; } catch (error) { throw new Error('Failed to connect to database'); } } export async function executeQuery(connection: mysql.Connection, query: string) { try { const [rows] = await connection.execute(query); return rows; } catch (error) { throw new Error(`Failed to execute query: ${error}`); } } export async function getTables(connection: mysql.Connection) { try { const [rows] = await connection.execute('SHOW TABLES'); return Object.values(rows).map((row: any) => Object.values(row)[0]); } catch (error) { throw new Error('Failed to fetch tables'); } } export async function getTablesList(connection: mysql.Connection) { try { const [rows] = await connection.execute('SHOW TABLES'); return Object.values(rows).map((row: any) => Object.values(row)[0]); } catch (error) { throw new Error('Failed to fetch tables list'); } }