orchestrate
Advanced tools
Comparing version 0.3.16 to 0.4.0
@@ -85,2 +85,18 @@ // Copyright 2014 Orchestrate, Inc. | ||
/** | ||
* Increase the value at the specified JSON document path by the given number | ||
* @param {string} path - JSON document path; delimtied by periods or slashes | ||
* @param {Object} value - Number by which to increase the value | ||
*/ | ||
PatchBuilder.prototype.inc = function (path, value) { | ||
assert(path, 'Inc requires a path parameter.'); | ||
var op = { | ||
op: "inc", | ||
path: path, | ||
}; | ||
if (value) op.value = value; | ||
this._ops.push(op); | ||
return this; | ||
}; | ||
/** | ||
* return {Promise} | ||
@@ -87,0 +103,0 @@ */ |
@@ -10,2 +10,3 @@ // Copyright 2013 Bowery Software, LLC | ||
var Builder = require('./builder') | ||
var BucketBuilder = require('./bucket_builder'); | ||
@@ -74,2 +75,76 @@ /** | ||
/** | ||
* Add new aggregate parameter. | ||
* @param {string} type | ||
* @param {string} path | ||
* @param {string} value | ||
* @return {SearchBuilder} | ||
*/ | ||
SearchBuilder.prototype.aggregate = function (type, path, value) { | ||
assert(type, 'type required'); | ||
assert(path, 'path required'); | ||
var _aggregate = [path, type, value].join(':'); | ||
if (this._aggregate) | ||
this._aggregate = [this._aggregate, _aggregate].join(','); | ||
else | ||
this._aggregate = _aggregate; | ||
return this; | ||
} | ||
/** | ||
* Add new 'stats' aggregate parameter. | ||
* @param {string} type | ||
* @param {string} path | ||
* @param {string} value | ||
* @return {SearchBuilder} | ||
*/ | ||
SearchBuilder.prototype.stats = function (path) { | ||
return this.aggregate('stats', path); | ||
} | ||
/** | ||
* Add new 'range' aggregate parameter. | ||
* @param {string} type | ||
* @param {string} path | ||
* @param {string} value | ||
* @return {SearchBuilder} | ||
*/ | ||
SearchBuilder.prototype.range = function (path, buckets) { | ||
var _buckets = buckets; | ||
if (typeof(buckets) === 'function') { | ||
_buckets = buckets(new BucketBuilder()); | ||
if (_buckets.build) _buckets = _buckets.build(); | ||
} | ||
return this.aggregate('range', path, _buckets); | ||
} | ||
/** | ||
* Add new 'distance' aggregate parameter. | ||
* @param {string} type | ||
* @param {string} path | ||
* @param {string} value | ||
* @return {SearchBuilder} | ||
*/ | ||
SearchBuilder.prototype.distance = function (path, buckets) { | ||
var _buckets = buckets; | ||
if (typeof(buckets) === 'function') { | ||
_buckets = buckets(new BucketBuilder()); | ||
if (_buckets.build) _buckets = _buckets.build(); | ||
} | ||
return this.aggregate('distance', path, _buckets); | ||
} | ||
/** | ||
* Add new 'time_series' aggregate parameter. | ||
* @param {string} type | ||
* @param {string} path | ||
* @param {string} value | ||
* @return {SearchBuilder} | ||
*/ | ||
SearchBuilder.prototype.time_series = function (path, time) { | ||
return this.aggregate('time_series', path, time); | ||
} | ||
/** | ||
* Set query. | ||
@@ -98,3 +173,4 @@ * @param {string} query | ||
offset: this._offset, | ||
sort: this._sort | ||
sort: this._sort, | ||
aggregate: this._aggregate | ||
}) | ||
@@ -101,0 +177,0 @@ |
@@ -28,3 +28,3 @@ { | ||
}, | ||
"version": "0.3.16", | ||
"version": "0.4.0", | ||
"main": "index", | ||
@@ -49,7 +49,7 @@ "tags": [ | ||
"scripts": { | ||
"test": "npm run cov && ./node_modules/.bin/mocha -u tdd -t 5000", | ||
"cov": "./node_modules/.bin/jscoverage lib lib-cov", | ||
"report": "npm run cov && ./node_modules/.bin/mocha -u tdd -R html-cov > coverage.html", | ||
"coveralls": "npm run cov && ./node_modules/.bin/mocha -u tdd -R mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js" | ||
"test": "npm run cov && mocha -u tdd -t 5000", | ||
"cov": "jscoverage lib lib-cov", | ||
"report": "npm run cov && mocha -u tdd -R html-cov -t 5000 > coverage.html", | ||
"coveralls": "npm run cov && mocha -u tdd -t 5000 -R mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js" | ||
} | ||
} |
@@ -257,2 +257,23 @@ # orchestrate.js [![Build Status](https://travis-ci.org/orchestrate-io/orchestrate.js.png)](https://travis-ci.org/orchestrate-io/orchestrate.js) [![Coverage Status](https://coveralls.io/repos/orchestrate-io/orchestrate.js/badge.png)](https://coveralls.io/r/orchestrate-io/orchestrate.js) | ||
.sort('age', 'asc') | ||
.aggregate('stats', 'value.name') | ||
.stats('username') | ||
// these two range aggregates are identical | ||
// but they use different interfaces | ||
.range('coolness', '*~1:1~2:2~*') | ||
.range('radness', function (builder) { | ||
return builder | ||
.before(1) | ||
.between(1, 2) | ||
.after(2); | ||
}) | ||
// these two distance aggregates are identical | ||
// but they use different interfaces | ||
.distance('location', '*~1:1~2:2~*') | ||
.distance('hometown', function (builder) { | ||
return builder | ||
.before(1) | ||
.between(1, 2) | ||
.after(2); | ||
}) | ||
.time_series('path', 'day') | ||
.query('steve') | ||
@@ -259,0 +280,0 @@ ``` |
@@ -100,3 +100,32 @@ // Copyright 2014 Orchestrate, Inc. | ||
// Geo-search | ||
// TODO Geo-search | ||
// Aggregates | ||
test('Search aggregates', function (done) { | ||
db.newSearchBuilder() | ||
.collection('users') | ||
.aggregate('stats', 'value.name') | ||
.stats('value.username') | ||
.range('value.coolness', '*~1:1~2:2~*') | ||
.range('value.radness', function (builder) { | ||
return builder | ||
.before(1) | ||
.between(1, 2) | ||
.after(2); | ||
}) | ||
.distance('value.location', '*~1:1~2:2~*') | ||
.distance('value.hometown', function (builder) { | ||
return builder | ||
.before(1) | ||
.between(1, 2) | ||
.after(2); | ||
}) | ||
.time_series('path', 'day') | ||
.query('value.location:NEAR:{latitude:12.3 longitude:56.7 radius:100km}') | ||
.then(function (res) { | ||
assert.equal(200, res.statusCode); | ||
done(); | ||
}) | ||
.fail(done); | ||
}); | ||
}); |
67661
21
1582
426