Skip to content

Commit

Permalink
refact
Browse files Browse the repository at this point in the history
  • Loading branch information
i5ting committed Jun 1, 2015
1 parent ca1e562 commit 8a642b8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 79 deletions.
72 changes: 1 addition & 71 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,71 +1 @@

function MongooseDao (Model){
/*if(typeof Model === 'undefined' || Model == null)
throw new Error('Model can not be null.');
*/
this.model = Model;
}

MongooseDao.prototype.create = function (doc,callback){
this.model.create(doc, function (error) {
if(error) return callback(error);

return callback(null);
});
};

MongooseDao.prototype.getById = function (id, callback) {
this.model.findOne({_id:id}, function(error, model){
if(error) return callback(error,null);

return callback(null,model);
});
};

MongooseDao.prototype.countByQuery = function (query, callback) {
this.model.count(query, function(error, model){
if(error) return callback(error,null);

return callback(null,model);
});
};

MongooseDao.prototype.getByQuery = function (query,fileds,opt,callback) {
this.model.find(query, fileds, opt, function(error,model){
if(error) return callback(error,null);

return callback(null,model);
});
};


MongooseDao.prototype.getAll = function (callback) {
this.model.find({}, function(error,model){
if(error) return callback(error,null);

return callback(null, model);
});
};
/*
MongooseDao.prototype.getAllModelByOption = function (opt, callback) {
MongooseDao.getModelByQuery({},{},opt, callback);
};*/


MongooseDao.prototype.delete = function (query, callback){
this.model.remove(query, function(error){
if(error) return callback(error);

return callback(null);
});
};

MongooseDao.prototype.update = function( conditions, update ,options, callback) {
this.model.update(conditions, update, options, function (error) {
if(error) return callback(error);

return callback(null);
});
};

module.exports = MongooseDao;
module.exports = require('./lib/dao');
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mongoosedao",
"version": "1.0.0",
"description": "",
"version": "1.0.1",
"description": "mongoose dao",
"main": "index.js",
"scripts": {
"start":"npm publish .",
Expand Down
8 changes: 2 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
require('../db');
require('./db');


Meeting = require('./Meeting');

var Meeting = require('./Meeting');

Meeting.create({"username":"sss","password":"password"},function(err, user){
console.log(user);
});



Meeting.delete({"username":"sss","password":"password"},function(err, user){
console.log(user);
});

0 comments on commit 8a642b8

Please sign in to comment.