Last active
February 25, 2019 05:09
-
-
Save herudi/b79f7e5877e1e7064cbfa681f27743a0 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
var mysql = require('mysql'); | |
var util = require('util'); | |
var connection = mysql.createConnection({ | |
host : 'localhost', | |
user : 'root', | |
password : '', | |
database : 'expressmysql', | |
dateStrings: 'date' | |
}); | |
//for query param like id=:id | |
connection.config.queryFormat = function (query, values) { | |
if (!values) return query; | |
return query.replace(/\:(\w+)/g, function (txt, key) { | |
if (values.hasOwnProperty(key)) { | |
return this.escape(values[key]); | |
} | |
return txt; | |
}.bind(this)); | |
}; | |
//enable async await | |
connection.query = util.promisify(connection.query); | |
module.exports = connection; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment