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

dotenv.config()
const connection = await mysql.createPool({
    host: process.env.DB_HOST,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_NAME,
    multipleStatements: true
})


const prepareDb = async()=>{
    try {
        const sql = fs.readFileSync("./sql/schemas.sql", "utf8")
        await connection.query(sql)
        console.log("Database created successfully")
    } catch (error) {
        console.log(error)
    }
}

export { connection, prepareDb }