const mysql2 = require('mysql2'); const db = require('../configs/config.json') const pool = mysql2.createPool( { connectionLimit: 20, host: db.database.host, user: db.database.user, password: db.database.password, database: db.database.database, port:db.database.port } ); exports.executequery = function (query) { return new Promise((result, reject) => { // //console.log(pool); // get the connection for connection pool pool.getConnection((error, connection) => { // if error during getting connection if (error) { //console.log("Connection Error -->>", error); reject(error) } else { //console.log("db connected"); connection.query(query, function (err, rows, fields) { connection.release(); if (err) { result(err); }; result(rows); }); } }); }); } exports.executevaluesquery = function (query, values) { return new Promise((result, reject) => { // get the connection for connection pool pool.getConnection((error, connection) => { if (error) { //console.log("Connection Error -->>", error); reject(error) } else { connection.query(query, values, function (err, rows, fields) { //release Conncetion connection.release(); if (err) { reject(err); }; result(rows); }); } }); }); }