from 'mysql';
import { promisify } from 'util';
const pool = mysql.createPool({ /** config **/ })
const promisePool = promisify(pool.query)
const updateStudentName = async () => {
await promisePool('UPDATE students SET name = "ERIC" where id = 1')
}
updateStudentName()and it does not update the table
however when i use this one
import mysql from 'mysql';
const pool = mysql.createPool({ /** config **/ })
const promisePool = (sql) => new Promise((resolve, reject) => {
pool.query(sql, (err, results) => {
if (err) {
return reject(err)
}
return resolve(results)
})
})
const updateStudentName = async () => {
await promisePool('UPDATE students SET name = "ERIC" where id = 1')
}
updateStudentName()then it works, how to correctly use promisify?
I'd try https://www.npmjs.com/package/doasync
Обсуждают сегодня