I have a problem in Nodejs when trying to make a connection with my db via getConnection method. I declared my db variable via require which is a createPool promise(as shown below). when i try to make a connection with that pool via getConnection it skips that code block.
const pool = mysql.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
database: process.env.DB_NAME,
password: process.env.DB_PASSWORD,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0
});
const db = pool.promise(); // this is exported
my connection method:
console.log('start');
const items = [this.idplace,this.idactivity,this.iduser,this.date,this.hour,this.party_size];
db.getConnection(function(err, conn) {
if(err) {
console.log('error when connecting to db:', err);
db.releaseConnection(conn);
throw err;
}
console.log('ok');
conn.execute(`INSERT INTO reservation(place,activity,customer,date,hour,party_size)VALUES(?,?,?,'?','?',?);`, items);
db.releaseConnection(conn);
});
console.log('end');
and the log is: start end (no sign of the logs inside db.getConnection)
What do you think is the reason of that?