const mysql = require('mysql2');
const dotenv = require('dotenv');

dotenv.config();

const pool = mysql.createPool({
    host: process.env.DB_HOST,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_NAME,
    waitForConnections: true,
    connectionLimit: 10,
    queueLimit: 0
});

// Convert pool to allow async/await
const promisePool = pool.promise();

console.log(`Intentando conectar a DB: ${process.env.DB_NAME} en ${process.env.DB_HOST}`);

module.exports = promisePool;
