import mysql from "mysql2/promise";
import dotenv from "dotenv";

dotenv.config();

const {
  DB_HOST = "127.0.0.1",
  DB_PORT = "3306",
  DB_USER = "root",
  DB_PASSWORD = "",
  MYSQL_HOST,
  MYSQL_USER,
  MYSQL_PASSWORD,
} = process.env;

const host = MYSQL_HOST || DB_HOST;
const user = MYSQL_USER || DB_USER;
const password =
  MYSQL_PASSWORD !== undefined ? MYSQL_PASSWORD : DB_PASSWORD;

const HSE_DATABASE = "hse";

export const pool = mysql.createPool({
  host,
  port: Number(DB_PORT),
  user,
  password,
  database: HSE_DATABASE,
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0,
});
