-1
Hello!
Analyzing my source code I realized that within the project there is a part that repeats many times.
I would like to reuse repetitive code in my mysql project
const pool = mysql.createPool(config)
return new Promise((resolve, reject)=>{
const queryString = `SELECT ...`
pool.getConnection((error, connection)=>{
if(error){
return
}
connection.query(queryString, (err, result)=>{
connection.release()
if(err) {
return false
}
resolve(result)
})
})
})
Where in the query will be used other querys, such as INSERTS, UPDATE, SELECTS
I saw that you can use callbacks
`
const conn = pool.getConnection((error, connection)=>{
callback(error,connection)
})
But when using the query, it says it is Undefined
const con = conn.connection
con.connection.query( 'SELECT ...', err, result )
con.release();
I am voting against, because is there a problem in the answer that I can improve? or is it wrong?
– novic