Comparing version 0.7.1 to 0.8.0
0.8.0 / 2014-03-01 | ||
================== | ||
* added `distinct` support (fixes #52) | ||
* added `Promise#then` | ||
0.7.1 / 2013-03-03 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -418,2 +418,35 @@ | ||
/** | ||
* distinct | ||
* | ||
* @param {String} distinct field to select | ||
* @param {Object} optional, query | ||
* @param {Function} completion callback | ||
* @return {Promise} | ||
* @api public | ||
*/ | ||
Collection.prototype.distinct = function (field, query, fn) { | ||
if ('function' == typeof query) { | ||
fn = query; | ||
query = {}; | ||
} | ||
var promise = new Promise(this, 'distinct'); | ||
if (fn) { | ||
promise.complete(fn); | ||
} | ||
// cast | ||
query = this.cast(query); | ||
// query | ||
debug('%s distinct %s (%j)', this.name, field, query); | ||
promise.query = query; | ||
this.col.distinct(field, query, promise.fulfill); | ||
return promise; | ||
}; | ||
/** | ||
* count | ||
@@ -420,0 +453,0 @@ * |
@@ -6,3 +6,4 @@ | ||
var EventEmitter = require('events').EventEmitter; | ||
var EventEmitter = require('events').EventEmitter | ||
, MPromise = require('mpromise'); | ||
@@ -97,1 +98,13 @@ /** | ||
}; | ||
/** | ||
* [Promises/A+](http://promises-aplus.github.io/promises-spec/)-compliant `.then`. | ||
* | ||
* @api public | ||
*/ | ||
Promise.prototype.then = function() { | ||
var p = new MPromise; | ||
this.success(p.fulfill.bind(p)); | ||
this.error(p.reject.bind(p)); | ||
return p.then.apply(p, arguments); | ||
}; |
{ | ||
"name": "monk" | ||
, "version": "0.7.1" | ||
, "version": "0.8.0" | ||
, "main": "lib/monk.js" | ||
@@ -10,2 +10,3 @@ , "tags": ["mongodb", "mongo", "driver"] | ||
, "debug": "*" | ||
, "mpromise": "~0.4.1" | ||
} | ||
@@ -16,2 +17,5 @@ , "devDependencies": { | ||
} | ||
, "scripts": { | ||
"test": "make test" | ||
} | ||
} |
@@ -217,2 +217,21 @@ /*global expect*/ | ||
describe('distinct', function(){ | ||
it('should work', function(done){ | ||
users.insert({ distinct: 'a' }, function(err){ | ||
expect(err).to.be(null); | ||
users.insert({ distinct: 'a' }, function(err){ | ||
expect(err).to.be(null); | ||
users.insert({ distinct: 'b' }, function(err){ | ||
expect(err).to.be(null); | ||
users.distinct('distinct', function(err, docs){ | ||
expect(err).to.be(null); | ||
expect(docs).to.eql(['a', 'b']); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('updating', function () { | ||
@@ -335,3 +354,3 @@ it('should update', function (done) { | ||
}); | ||
}; | ||
} | ||
@@ -338,0 +357,0 @@ var rand = 'now-' + Date.now(); |
@@ -37,2 +37,30 @@ | ||
it('Promise#then', function () { | ||
var p = new Promise() | ||
, runCount = 0; | ||
p.then(function() { | ||
++runCount; | ||
}); | ||
setTimeout(function () { | ||
expect(runCount).to.be(1); | ||
}, 10); | ||
}); | ||
it('Promise#then-chain', function () { | ||
var p = new Promise() | ||
, runCount = 0; | ||
p.then(function () { | ||
++runCount; | ||
return new Promise(); | ||
}).then(function () { | ||
++runCount; | ||
}); | ||
setTimeout(function () { | ||
expect(runCount).to.be(2); | ||
}, 10); | ||
}); | ||
}); |
42661
1245
3
15
+ Addedmpromise@~0.4.1
+ Addedmpromise@0.4.4(transitive)