const mysql = require('mysql2/promise'); const dbConfig = { host: 'rm-t4na9qj85v7790tf84o.mysql.singapore.rds.aliyuncs.com', port: 3306, user: 'crawler_admin', password: 'cyber#crawler_2023', database: 'tools_auto_access', charset: 'utf8mb4', timezone: '+08:00', acquireTimeout: 60000, timeout: 60000, reconnect: true }; let pool; const createPool = () => { pool = mysql.createPool({ ...dbConfig, waitForConnections: true, connectionLimit: 10, queueLimit: 0 }); console.log('Database pool created'); return pool; }; const getConnection = async () => { if (!pool) { createPool(); } return await pool.getConnection(); }; const executeQuery = async (sql, params = []) => { const connection = await getConnection(); try { const [rows] = await connection.execute(sql, params); return rows; } catch (error) { console.error('Database query error:', error); throw error; } finally { connection.release(); } }; module.exports = { createPool, getConnection, executeQuery };