Created
September 9, 2017 19:33
-
-
Save b3tts32/6ca52f7443a6cc20b6ff9c21acb53368 to your computer and use it in GitHub Desktop.
MySQL Promise Module
This file contains hidden or 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 Promise = require('promise'); | |
//New comment for update | |
var pool = mysql.createPool({ | |
multipleStatements: true, | |
host: '192.168.94.27', | |
user: 'root', | |
database: 'test', | |
password: 'password', | |
dateStrings: 'date', | |
connectionLimit: 20, | |
}); | |
exports.execSQL = function(sql){ | |
return new Promise(function (resolve, reject) { | |
pool.getConnection(function(err,connection){ | |
if (err) reject(err); | |
connection.query(sql, function(err, rows, fields) { | |
if (err) reject(err); | |
resolve(rows); | |
}); | |
connection.release(); | |
}); | |
}) | |
} |
This file contains hidden or 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 db = require('./db'); | |
var sql = "SELECT * from test"; | |
db.execSQL(sql).then((data) => { | |
console.log(data); | |
}) | |
.catch((err) => { | |
console.log(err); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment