Skip to content

Instantly share code, notes, and snippets.

@rreimi
Last active August 29, 2015 14:23
Show Gist options
  • Save rreimi/5a3a125b19b50c60f5b0 to your computer and use it in GitHub Desktop.
Save rreimi/5a3a125b19b50c60f5b0 to your computer and use it in GitHub Desktop.
Node mysql wrapper
//#db.js
var mysql = require('mysql');
var pool = mysql.createPool({
connectionLimit : 100, //important
host : 'localhost',
user : 'root',
password : 'admin',
database : 'fantasy',
debug : false
});
function query(query, callback) {
pool.getConnection(function(err, conn){
if (err) {
conn.release();
callback(err);
} else {
conn.query(query, function(err, rows, fields) {
conn.release();
if (err) throw err;
callback(err, rows, fields);
});
}
});
}
function statement(query, params, callback) {
pool.getConnection(function(err, conn){
if (err) {
conn.release();
callback(err);
} else {
conn.query(query, params, function(err, rows, fields) {
conn.release();
if (err) throw err;
callback(err, rows, fields);
});
}
});
}
var db = {}
db.query = query;
db.statement = statement;
module.exports = db;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment