require('dotenv').config()
var mysql = require('mysql')
var pool = mysql.createPool({
    connectionLimit: 10,
    port: process.env.DB_PORT,
    host: process.env.DB_HOST,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD ,
    database: process.env.DB_DATABASE ,})
    pool.getConnection((err, connection) => {
      if (err) {
          if (err.code === 'PROTOCOL_CONNECTION_LOST') {
              console.error('Database connection was closed.')
          }
          if (err.code === 'ER_CON_COUNT_ERROR') {
              console.error('Database has too many connections.')
          }
          if (err.code === 'ECONNREFUSED') {
              console.error('Database connection was refused.')
          }
      }

      if (connection) connection.release()
      return
  })

  module.exports = pool;
