const mysql = require('mysql2/promise'); let pool; function initPool() { if (pool) { pool.end().catch(e => console.error('Error closing pool:', e)); } pool = mysql.createPool({ host: process.env.MYSQL_HOST || 'localhost', port: parseInt(process.env.MYSQL_PORT) || 3306, user: process.env.MYSQL_USER || 'root', password: process.env.MYSQL_PASSWORD || '', database: process.env.MYSQL_DATABASE || 'display_wall', waitForConnections: true, connectionLimit: 10, queueLimit: 0 }); } initPool(); module.exports = { query: (...args) => pool.query(...args), initPool };