const mysql = require('mysql2')
require('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
}).promise()

const dbconn = async() => {
    try{
    const connection = await pool.getConnection()
    console.log('db connected successfully')
    connection.release()
    return true
    }catch(error){
        console.error('db connection failed', error.message)
        return false
    }
}
dbconn()

module.exports = {pool, dbconn}
