Last active
March 11, 2017 00:19
-
-
Save rictorres/42043fcc26ed9de2e56f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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