import mysql from "mysql2/promise"

let pool

export function getMysqlPool() {
  if (pool) {
    return pool
  }

  const config = useRuntimeConfig()

  pool = mysql.createPool({
    host: config.mysqlHost,
    port: Number(config.mysqlPort || 3306),
    database: config.mysqlDatabase,
    user: config.mysqlUser,
    password: config.mysqlPassword,
    waitForConnections: true,
    connectionLimit: 10,
    queueLimit: 0,
    charset: "utf8mb4",
  })

  return pool
}
