Created
March 28, 2013 09:54
-
-
Save kohlikohl/5262056 to your computer and use it in GitHub Desktop.
Improvement?
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 = module.exports = function (conf) { | |
var poolConfig = { | |
name: 'mysql', | |
create: this._createConnection.bind(this), | |
destroy: this._destroyConnection, | |
max: 10 | |
}; | |
this._conf = conf; | |
this._pool = pool.Pool(poolConfig); | |
}; | |
Mysql.prototype._createConnection = function (callback) { | |
var config = { | |
"hostname": this._conf.get("mysql:hostname"), | |
"user": this._conf.get("mysql:user"), | |
"password": this._conf.get("mysql:password"), | |
"database": this._conf.get("mysql:database") | |
}; | |
new mysql.Database(config).connect( | |
function (error) { | |
if (error) { | |
callback(error, null); | |
} else { | |
callback(null, this); | |
} | |
} | |
); | |
}; | |
Mysql.prototype._destroyConnection = function (client) { | |
if (client) { | |
client.disconnect(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment