Skip to content

Instantly share code, notes, and snippets.

@rictorres
Last active March 11, 2017 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rictorres/42043fcc26ed9de2e56f to your computer and use it in GitHub Desktop.
Save rictorres/42043fcc26ed9de2e56f to your computer and use it in GitHub Desktop.
'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