Comparing version 0.8.6 to 0.8.7
@@ -0,1 +1,5 @@ | ||
## version 0.8.7 | ||
- Added support for 2i operations in map/reduce inputs | ||
## version 0.8.6 | ||
@@ -2,0 +6,0 @@ |
@@ -9,3 +9,3 @@ var Bucket = require('../bucket'); | ||
this.keyData = keyData; | ||
} | ||
}; | ||
@@ -42,2 +42,26 @@ var processInput = function processInput(spec) { | ||
// 2i searches | ||
if (spec.index) { | ||
if ((!spec.bucket) || | ||
(spec.start && !spec.end) || | ||
(spec.end && !spec.start) || | ||
(!spec.start && !spec.end && !spec.key)) { | ||
throw new restify.BadRequestError('Invalid 2i query'); | ||
} | ||
var keys; | ||
var bucket = Bucket.get(spec.bucket); | ||
if (spec.start) { | ||
keys = bucket.rangeQuery(spec.index, spec.start, spec.end); | ||
} else { | ||
keys = bucket.query(spec.index, spec.key); | ||
} | ||
return keys.map(function(key) { | ||
return new Input(bucket.getObject(key)); | ||
}); | ||
} | ||
// Key filters | ||
@@ -44,0 +68,0 @@ |
@@ -11,3 +11,3 @@ var Bucket = require('../models/bucket'); | ||
if (inputs.constructor.name !== 'Array') { | ||
return new restify.BadRequestError('Inputs must be passed as an array'); | ||
inputs = [inputs]; | ||
} | ||
@@ -14,0 +14,0 @@ |
{ | ||
"name": "mock-riak", | ||
"version": "0.8.6", | ||
"version": "0.8.7", | ||
"author": "Marco Tabini <marcot@tabini.ca>", | ||
@@ -5,0 +5,0 @@ "description": "A mock library that simulates a running Riak cluster (without actually having one)", |
@@ -9,37 +9,23 @@ var RiakClient = require('riak-js'); | ||
var payload = { name : 'Marco' , email : 'marcot@tabini.ca' }; | ||
var bucket = 'people1'; | ||
var key = 'randomkey124'; | ||
var payloads = [ { name : 'Marco' , email : 'marcot@tabini.ca' } , { name : 'Daniel' , email : 'daniel@example.org' } , { name : 'Andrea' , email : 'andrea@example.org' } ]; | ||
var bucket = 'things'; | ||
async.waterfall( | ||
[ | ||
async.each( | ||
payloads, | ||
function initialSave(callback) { | ||
client.save(bucket, key, payload, { index : { index1 : 'a' , index2 : 'b' } }, callback); | ||
}, | ||
function retrieve(doc, meta, callback) { | ||
client.get(bucket, key, callback); | ||
}, | ||
function checkMeta(doc, meta, callback) { | ||
doc = JSON.parse(doc); | ||
expect(doc).to.be.an('object'); | ||
expect(doc).to.deep.equal(payload); | ||
expect(meta).to.be.an('object'); | ||
expect(meta._headers['x-riak-index-index1_bin']).to.equal('a'); | ||
expect(meta._headers['x-riak-index-index2_bin']).to.equal('b'); | ||
callback(); | ||
} | ||
function iterator(element, callback) { | ||
client.save(bucket, null, element, { index : { email_index : element.email } }, callback); | ||
}, | ||
], | ||
function(err) { | ||
expect(err).to.be.undefined; | ||
expect(err).to.be.null; | ||
done(); | ||
client.mapreduce | ||
.add({ bucket : bucket , index : 'email_index_bin' , key : 'danielkkk@example.org' }) | ||
.map('Riak.mapValuesJson') | ||
.run(function(err, result) { | ||
console.log(err); | ||
console.log(result); | ||
}); | ||
} | ||
); |
@@ -151,2 +151,34 @@ var Riak = require('../index'); | ||
}); | ||
it('should support 2i operations in input', function(done) { | ||
var payloads = [ { name : 'Marco' , email : 'marcot@tabini.ca' } , { name : 'Daniel' , email : 'daniel@example.org' } , { name : 'Andrea' , email : 'andrea@example.org' } ]; | ||
var bucket = 'things22'; | ||
async.each( | ||
payloads, | ||
function iterator(element, callback) { | ||
client.save(bucket, null, element, { index : { email_index : element.email } }, callback); | ||
}, | ||
function(err) { | ||
expect(err).to.be.null; | ||
client.mapreduce | ||
.add({ bucket : bucket , index : 'email_index_bin' , key : 'daniel@example.org' }) | ||
.map('Riak.mapValuesJson') | ||
.run(function(err, result) { | ||
expect(err).to.be.null; | ||
expect(result).to.be.an('array'); | ||
expect(result).to.have.length(1); | ||
expect(result[0]).to.be.an('object'); | ||
expect(result[0]).to.deep.equal(payloads[1]); | ||
done(); | ||
}); | ||
} | ||
); | ||
}); | ||
@@ -153,0 +185,0 @@ after(function (done) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79856
1631