Skip to content
This repository has been archived by the owner on Dec 23, 2018. It is now read-only.

Commit

Permalink
added insert / update / remove
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Condon committed Apr 12, 2012
1 parent 14cbb54 commit f278085
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
65 changes: 62 additions & 3 deletions src/common/collection.js
@@ -1,4 +1,4 @@

var Cursor = require('./cursor');

/**
* wrapper for the drivers
Expand Down Expand Up @@ -34,11 +34,70 @@
/**
*/

"find": function(selector, options, next) {
"find": function(selector, options) {
return new Cursor(this, selector || {}, options || {}, this._modelClass);
},

/**
*/

if(!next) {
"findOne": function(selector, options, next) {

if(typeof selector == 'function') {
next = selector;
selector = undefined;
options = undefined;
}
else
if(typeof options == 'function') {
next = options;
options = undefined;
}

this.find(selector, options).limit(1).toArray(function(err, items) {
if(err) return next(err);
return next(null, items);
});
},


/**
*/


"insert": function(item, next) {
var items = item instanceof Array ? item : [item],
self = this;

this.next(function() {
self.collection.insert(items, self._wrap(next || function(){}, this));
});
},

/**
*/

"update": function(selector, toUpdate, options, next) {
var self = this;

if(typeof options == 'function') {
next = options;
options = undefined;
}

this.next(function() {
self.collection.update(selector, toUpdate, options || {}, self._wrap(next || function(){}, this))
});
},

/**
*/

"remove": function(selector, next) {
var self = this;
this.next(function() {
self.colletion.remove(selector, self._wrap(next || function(){}, next));
});
}

});
Expand Down
1 change: 1 addition & 0 deletions src/common/drivers/memory/cursor.js
Expand Up @@ -15,6 +15,7 @@ var Cursor = require("../../abstract/cursor").extend({
});
},


/**
*/

Expand Down

0 comments on commit f278085

Please sign in to comment.