Created
December 27, 2013 17:45
-
-
Save riston/8150244 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 MongoClient = require('mongodb').MongoClient, | |
config = require('easy-config'); | |
var DB = function () { | |
function connect (cb) { | |
MongoClient.connect(config.mongodb.url, function (err, db) { | |
if (err) { | |
throw new Error('Connection error, this needs better handling! ', err); | |
} else { | |
return cb(db); | |
} | |
}); | |
} | |
return { | |
get: connect | |
}; | |
}(); | |
module.exports = DB; |
This file contains hidden or 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
'use strict'; | |
var User = function (db) { | |
var collection = db.collection('users'); | |
function find (cb) { | |
collection.find().toArray(function (err, users) { | |
if (err) { | |
return cb(err); | |
} | |
return cb(null, users); | |
}); | |
} | |
function create () { | |
} | |
return { | |
find: find, | |
create: create | |
}; | |
}; | |
module.exports = User; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment