Skip to content

Instantly share code, notes, and snippets.

@leemason
Created May 5, 2016 13:55
Show Gist options
  • Save leemason/76c27eb6bc8173de5bce31fd99674864 to your computer and use it in GitHub Desktop.
Save leemason/76c27eb6bc8173de5bce31fd99674864 to your computer and use it in GitHub Desktop.
Facade/Implicit Invocation
let DB = require('db_facade');
// Now you can use DB as its already created, this means we dont need to create it everywhere we use it.
export default class Controller{
postIndex(req, res){
DB.insert('table', req.get('data'));
}
}
let db = require('db_module'),
config = require('config');
let DB = new db(config.db);
export default DB;
//example of a module that needs "something" to be given for its usage
export default class DB{
constructor(config){
this.config = config;
}
select(){
// select code
}
insert(){
// insert
}
// etc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment