Is there a way to use pool.getConnection() taken from the mysqljs/mysql lib with the async/ await syntax?
The idea is to have a method whic
Previous answers (with util.promisify) did not work for me, and only implementing Promise manually works:
Function:
async function removeItem (id) {
return new Promise( (resolve) => {
pool.query('DELETE FROM table_name WHERE id=' + id, (error) => {
resolve ({result: !error});
});
});
}
Usage:
const app = express();
const mysql = require('mysql');
const pool = mysql.createPool({
connectionLimit: 10,
host: 'localhost',
user: 'login',
password: 'pass',
database: 'dbname'
});
app.post("/:id", async (req, res) => {
const answer = await itemRemove(id);
res.send(answer);
});