Ive found examples of how to promisify a query for connection = mysql.createConnection(config); and found examples on how to promisify pool.query for pool = mysql.createPool(config);, the issue is that all examples relating to pools either use a transaction without promisify async/await, or they use a pool.query which doesnt work with transactions since each use gets a new connection.
Basically, im expecting code something like this...
const mysql = require('mysql');
const util = require('util');
const pool = mysql.createPool(config);
const pool.getConnection = util.promisify(pool.getConnection).bind(pool);
const connection = pool.getConnection;
let sql = SOME SQL;
let sql2 = MORE SQL;
await connection.beginTransaction();
const results = await query(sql);
const results2 = await query(sql2);
await connection.commit();
await connection.release();
but the only working example i can seem to find is this...
pool.getConnection(function(err, connection)
{
if (err) throw err; // not connected!
// Use the connection
connection.query('SELECT something FROM sometable', function (error, results, fields)
{
// When done with the connection, release it.
connection.release();
// Handle error after the release.
if (error) throw error;
// Don't use the connection here, it has been returned to the pool.
});
});
its like you are required to mix both formats. i normally figure this stuff out on my own but im at a complete loss here and cant find any docs regarding this either. At this point im assuming im just supposed to mix the formats or abandon this and find something that uses mysql that does what i want/expect.