Comparing version 0.1.3 to 0.2.0
@@ -23,11 +23,21 @@ | ||
function returnFirst (err, res) { | ||
if (err) { return cb(err); } | ||
cb(null, res.length > 0 ? res[0] : null); | ||
function cbWriteCount (err, res) { | ||
if (err) return cb(err); | ||
cb(null, res.result.n); | ||
} | ||
function cbFirstOp (err, res) { | ||
if (err) return cb(err); | ||
cb(null, res.ops[0]); | ||
} | ||
function cbAllOps (err, res) { | ||
if (err) return cb(err); | ||
cb(null, res.ops); | ||
} | ||
switch (this.op) { | ||
case 'findById': | ||
debug('findById(%s)', this.args[0].toString()); | ||
debug('findOne({ _id: %s })', this.args[0].toString()); | ||
col.findOne({ _id: this.args[0] }, null, this.opts, cb); | ||
@@ -57,14 +67,29 @@ break; | ||
case 'insert': | ||
debug('insert(%o)', this.args[0]); | ||
col.insert(this.args[0], this.opts, (Array.isArray(this.args[0]) ? cb : returnFirst)); | ||
if (Array.isArray(this.args[0])) { | ||
debug('insertMany(%o)', this.args[0]); | ||
col.insertMany(this.args[0], this.opts, cbAllOps); | ||
} else { | ||
debug('insertOne(%o)', this.args[0]); | ||
col.insertOne(this.args[0], this.opts, cbFirstOp); | ||
} | ||
break; | ||
case 'update': | ||
debug('update(%o, %o)', this.args[0], this.args[1]); | ||
col.update(this.args[0], this.args[1], this.opts, cb); | ||
if (this.opts.multi === true) { | ||
debug('updateMany(%o, %o)', this.args[0], this.args[1]); | ||
col.updateMany(this.args[0], this.args[1], this.opts, cbWriteCount); | ||
} else { | ||
debug('updateOne(%o, %o)', this.args[0], this.args[1]); | ||
col.updateOne(this.args[0], this.args[1], this.opts, cbWriteCount); | ||
} | ||
break; | ||
case 'remove': | ||
debug('remove(%o)', this.args[0]); | ||
col.remove(this.args[0], this.opts, cb); | ||
if (this.opts.single === true) { | ||
debug('removeOne(%o)', this.args[0]); | ||
col.removeOne(this.args[0], this.opts, cbWriteCount); | ||
} else { | ||
debug('removeMany(%o)', this.args[0]); | ||
col.removeMany(this.args[0], this.opts, cbWriteCount); | ||
} | ||
break; | ||
@@ -71,0 +96,0 @@ |
{ | ||
"name": "albatross", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
"author": "Linus Unnebäck <linus@folkdatorn.se>", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"repository": { | ||
@@ -11,8 +14,8 @@ "type": "git", | ||
"dependencies": { | ||
"debug": "^2.1.0", | ||
"mongodb": "^1.4.22" | ||
"debug": "^2.2.0", | ||
"mongodb": "^2.0.33" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.0.1" | ||
"mocha": "^2.2.5" | ||
} | ||
} |
32714
537
+ Addedbson@1.0.9(transitive)
+ Addedbuffer-shims@1.0.0(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedes6-promise@3.2.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmongodb@2.2.36(transitive)
+ Addedmongodb-core@2.1.20(transitive)
+ Addedprocess-nextick-args@1.0.7(transitive)
+ Addedreadable-stream@2.2.7(transitive)
+ Addedrequire_optional@1.0.1(transitive)
+ Addedresolve-from@2.0.0(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedstring_decoder@1.0.3(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedabort-controller@3.0.0(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbson@0.2.22(transitive)
- Removedbuffer@6.0.3(transitive)
- Removedevent-target-shim@5.0.1(transitive)
- Removedevents@3.3.0(transitive)
- Removedieee754@1.2.1(transitive)
- Removedkerberos@0.0.11(transitive)
- Removedmongodb@1.4.40(transitive)
- Removednan@1.8.4(transitive)
- Removedprocess@0.11.10(transitive)
- Removedreadable-stream@4.7.0(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedstring_decoder@1.3.0(transitive)
Updateddebug@^2.2.0
Updatedmongodb@^2.0.33