Skip to content

Instantly share code, notes, and snippets.

@riston
Created December 27, 2013 17:45
Show Gist options
  • Save riston/8150244 to your computer and use it in GitHub Desktop.
Save riston/8150244 to your computer and use it in GitHub Desktop.
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;
'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