@@ -22,12 +22,12 @@ function MongooseDao (Model){
22
22
23
23
// create
24
24
MongooseDao . prototype . create = function ( doc , cb ) {
25
- this . model . create ( doc , cb ) ;
25
+ return this . model . create ( doc , cb ) ;
26
26
} ;
27
27
28
28
// read
29
29
MongooseDao . prototype . getById = function ( id , cb ) {
30
- this . model . findOne ( { _id :id } , cb ) ;
30
+ return this . model . findOne ( { _id :id } , cb ) ;
31
31
} ;
32
32
33
33
MongooseDao . prototype . count = function ( ) {
@@ -41,30 +41,30 @@ MongooseDao.prototype.count = function() {
41
41
//default : count(cb)
42
42
cb = arguments [ 0 ] ;
43
43
}
44
- this . model . count ( query , cb ) ;
44
+ return this . model . count ( query , cb ) ;
45
45
} ;
46
46
47
47
MongooseDao . prototype . query = MongooseDao . prototype . find = MongooseDao . prototype . getByQuery = function ( query , cb ) {
48
- this . model . find ( query , cb ) ;
48
+ return this . model . find ( query , cb ) ;
49
49
} ;
50
50
51
51
MongooseDao . prototype . all = MongooseDao . prototype . getAll = function ( cb ) {
52
- this . model . find ( { } , cb ) ;
52
+ return this . model . find ( { } , cb ) ;
53
53
} ;
54
54
55
55
MongooseDao . prototype . one = MongooseDao . prototype . findOne = function ( query , cb ) {
56
- this . model . findOne ( query , cb ) ;
56
+ return this . model . findOne ( query , cb ) ;
57
57
} ;
58
58
59
59
// update
60
60
MongooseDao . prototype . updateById = function ( id , update , cb ) {
61
61
// console.log('MongooseDao.prototype.updateById' + update);
62
- this . updateOne ( { _id :id } , update , cb ) ;
62
+ return this . updateOne ( { _id :id } , update , cb ) ;
63
63
} ;
64
64
65
65
MongooseDao . prototype . updateOne = function ( conditions , update , cb ) {
66
66
// console.log('MongooseDao.prototype.updateById' + update);
67
- this . update ( conditions , update , { multi : false } , cb ) ;
67
+ return this . update ( conditions , update , { multi : false } , cb ) ;
68
68
} ;
69
69
70
70
// way1: conditions, update , cb
@@ -91,21 +91,21 @@ MongooseDao.prototype.update = function() {
91
91
var opt = { multi : true } ;
92
92
_extend ( opt , _options ) ;
93
93
94
- this . model . update ( conditions , update , opt , cb ) ;
94
+ return this . model . update ( conditions , update , opt , cb ) ;
95
95
} ;
96
96
97
97
// delete
98
98
MongooseDao . prototype . delete = MongooseDao . prototype . remove = function ( query , cb ) {
99
- this . model . remove ( query , cb ) ;
99
+ return this . model . remove ( query , cb ) ;
100
100
} ;
101
101
102
102
MongooseDao . prototype . deleteAll = MongooseDao . prototype . removeAll = function ( cb ) {
103
- this . delete ( { } , cb ) ;
103
+ return this . delete ( { } , cb ) ;
104
104
} ;
105
105
106
106
MongooseDao . prototype . deleteById = MongooseDao . prototype . removeById = function ( id , cb ) {
107
107
// console.log('MongooseDao.prototype.deleteById');
108
- this . delete ( { _id : id } , cb ) ;
108
+ return this . delete ( { _id : id } , cb ) ;
109
109
} ;
110
110
111
111
// pagination
@@ -136,7 +136,7 @@ MongooseDao.prototype.latest = MongooseDao.prototype.top = MongooseDao.prototype
136
136
cb = arguments [ 0 ] ;
137
137
}
138
138
139
- this . model . find ( q ) . sort ( sort ) . limit ( n ) . exec ( cb ) ;
139
+ return this . model . find ( q ) . sort ( sort ) . limit ( n ) . exec ( cb ) ;
140
140
} ;
141
141
142
142
// TODO: impl page by lastId
@@ -184,7 +184,7 @@ MongooseDao.prototype.pageByLastId = function(){
184
184
cb = arguments [ 1 ] ;
185
185
}
186
186
187
- this . model . find ( q ) . sort ( sort ) . limit ( n ) . exec ( cb ) ;
187
+ return this . model . find ( q ) . sort ( sort ) . limit ( n ) . exec ( cb ) ;
188
188
} ;
189
189
190
190
// private
0 commit comments