Skip to content

Instantly share code, notes, and snippets.

@groundwater
Created February 4, 2013 21:17
Show Gist options
  • Save groundwater/4709805 to your computer and use it in GitHub Desktop.
Save groundwater/4709805 to your computer and use it in GitHub Desktop.
function Database(mysql,config){
this.mysql = mysql;
this.config = config;
// setup mysql connection based on config
}
Database.prototype.get = function(){
// return an open mysql handle
// if mysql has re-connected, make sure
// you're returning the active connection
}
module.exports.inject = function(di){
return new Database(di.mysql,di.config);
}
var di = {};
di.config = require('./config');
// pass in the actual mysql library
di.mysql = require('mysql');
// setup your database
di.database = require('./database').inject(di);
// your app will have a fully connected database
di.app = require('./app').inject(di);
@diogogmt
Copy link

diogogmt commented Feb 4, 2013

Looking forward to that blog post :)

@groundwater
Copy link
Author

@diogogmt I have a draft here

https://gist.github.com/jacobgroundwater/ae7d6a4af43b71fed82a

I would appreciate any feedback you have. I'll publish to my blog later, once I get polish it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment