MySQL Async/Await Wrapper
Basic API for performing async/await MySQL queries on a pool. A new connection is created, queried, and released for each call to query()
.
Configuration:
{
connectionLimit : 10,
host : 'example.org',
user : 'bob',
password : 'secret',
database : 'my_db'
}
Example
const fs = require(`fs`);
const mysql = require(`mysql-await`);
(async () => {
const db = mysql(JSON.parse(fs.readFileSync(`mysql-config.json`)));
const result = await db.query(`SELECT * FROM transactions WHERE ticker = ?`, [`DE`]);
console.log(result);
db.end();
})();
Example Output
[ RowDataPacket {
id: 56,
account: 3,
commission: 7,
date: 2018-05-17T07:00:00.000Z,
price: 146.71,
shares: 20,
ticker: 'DE',
type: 1 },
RowDataPacket {
id: 112,
account: 3,
commission: 7,
date: 2018-05-21T07:00:00.000Z,
price: 158.83,
shares: -20,
ticker: 'DE',
type: 2 } ]
License
MIT