Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'use strict';
const mysql = require('mysql');
const Prom = require('bluebird');
Prom.promisifyAll(require('mysql/lib/Connection').prototype);
Prom.promisifyAll(require('mysql/lib/Pool').prototype);
let pool = mysql.createPool({
host: 'localhost',
user: 'user',
password: 'password',
database: 'database'
});
let getPoolConnection = () => pool.getConnectionAsync().disposer(
connection => connection.destroy()
);
let query = command => Prom.using(getPoolConnection(),
connection => connection.queryAsync(command)
);
module.exports = {
query: query,
escape: mysql.escape
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment