const mysql = require('mysql2/promise');

class DataBase {
    constructor() {
        this.con = mysql.createPool({
            host: process.env.DB_HOST,
            user: process.env.DB_USER,
            password: process.env.DB_PASSWORD,
            database: process.env.DB_DATABASE,
            dateStrings: true,
            waitForConnections: true,
            connectionLimit: 10,
            queueLimit: 0  
          });
    }

    // Konektor
    getConnection() {
        return this.con;
    }

    // Wykonaj zapytanie
    async Commit(sql, data) {
        const [rows] = await this.con.execute(sql, data);
        return rows;
    }
}

module.exports = new DataBase();