Answer the question
In order to leave comments, you need to log in
Connection pool and how it works?
Hello to all!
There is a code:
const mysql = require("mysql2");
const pool = mysql.createPool({
host: "localhost",
user: "use",
database: "dadb",
password: "pass"
}).promise();
const sql = 'SELECT secret FROM validation_table WHERE name=?;'
const name = 'flowerr'
pool.query(sql,name)
.then(result =>{
let res = result[0]
console.log('result = ',res[0]);
pool.end();
})
.then(() =>{
console.log("end");
})
.catch(function(err) {
console.log(err.message);
})
result = undefined
end
Answer the question
In order to leave comments, you need to log in
.then(result =>{
let res = result[0]
console.log('result = ',res[0]);
pool.end();
if( result === undefined ) throw new Error();
})
.then(() =>{
console.log("end");
})
.catch(function(err) {
console.log(err.message);
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question