Created
June 15, 2012 10:28
-
-
Save guileen/2935761 to your computer and use it in GitHub Desktop.
bad style?
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
// ------------ | |
// config.js | |
module.exports = {mongo: 'mongo://localhost/test'}; | |
// ----------- | |
// index.js | |
var mongoskin = require('mongoskin'); | |
// init config | |
var config = require('./config'); | |
config.db = mongoskin.db(config.db); | |
exports.user = require('./user'); | |
exports.book = require('./book'); | |
// ---------- | |
// user.js | |
var config = require('./config'); | |
var db = config.db; | |
var User = db.collection('user'); | |
exports.get = function(id, callback) { | |
User.findById(id, callback); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@fengmk2 我觉得问题是缺少“依赖注入”。我很讨厌依赖注入,不过在把数据访问层独立出来的时候,似乎又需要它。