Closed HoldYourWaffle closed 4 years ago
Promises are already implemented in the types. You can use mysql2 with promises with a slightly different import statement: import mysql from 'mysql2/promise';
After that import you can use mysql2 with promises. Simple example:
import mysql, { Pool } from 'mysql2/promise';
let mysqlPool: Pool = mysql.createPool({
/* Connection params */
});
mysqlPool
.execute(queryString)
.then(
(result): void => {
console.log('Query executed!');
console.log(result);
},
)
.catch(
(error): void => {
console.log('Something went wrong...');
console.log(error.message);
},
);
Hope this helps you out.
I know how to use mysql2 in 'promise mode' but I'm referring to the promise()
function on Pool
and Connection
used to 'upgrade' the standard variants (as mentioned in the third and fourth block of the linked section).
Please, consider this PR. I have same problem in my project and forced to use a workaround to fix this issue. This fix looks great.
These typings are unfortunately out of date, missing at least the
promise()
shortcut function onPool
andConnection
.I would love to contribute a PR to fix this but I don't know this library well enough to know what the return type would be.