mysqljs / mysql

A pure node.js JavaScript Client implementing the MySQL protocol.
MIT License
18.31k stars 2.53k forks source link

Use this with async / await? #2525

Closed blaasvaer closed 3 years ago

blaasvaer commented 3 years ago

I've been using the npm package 'pg' and need to switch to this npm package 'mysql'. And I've been using the 'pg' package like this:

    const res = await pool.query( query );

But since the 'mysql' package uses a callback, I need to do this:

    const res = await pool.query( query, function ( error, results, fields ) { return results; // ABBREVIATED } );

The callback gets fired immediately and does not return to the calling function ... now, how do I make this package work with the above method? I don't know whether this is an actual 'issue' or the package is simply just not Promisified.

blaasvaer commented 3 years ago

Well, the simple solution is to wrap the whole thing in a new Promise and return it.