fix nin support for in memory datasource
This commit is contained in:
parent
dd4530cad6
commit
a3ae44aca0
|
@ -267,7 +267,7 @@ Memory.prototype.findOrCreate = function(model, filter, data, callback) {
|
|||
callback(null, found, false);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
self._models[model].model.include(nodes[0], filter.include, {}, function(err, nodes) {
|
||||
process.nextTick(function() {
|
||||
if (err) return callback(err);
|
||||
|
@ -403,7 +403,7 @@ Memory.prototype._findAllSkippingIncludes = function(model, filter) {
|
|||
nodes = nodes.slice(skip, skip + limit);
|
||||
}
|
||||
return nodes;
|
||||
|
||||
|
||||
function sorting(a, b) {
|
||||
var undefinedA, undefinedB;
|
||||
|
||||
|
@ -558,6 +558,15 @@ function applyFilter(filter) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (example.nin) {
|
||||
for (var i = 0; i < example.nin.length; i++) {
|
||||
if (example.nin[i] == value) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if ('neq' in example) {
|
||||
return compare(example.neq, value) !== 0;
|
||||
}
|
||||
|
@ -764,7 +773,7 @@ Memory.prototype.replaceOrCreate = function(model, data, options, callback) {
|
|||
var found = nodes[0];
|
||||
|
||||
if (!found) {
|
||||
// Calling _createSync to update the collection in a sync way and
|
||||
// Calling _createSync to update the collection in a sync way and
|
||||
// to guarantee to create it in the same turn of even loop
|
||||
return self._createSync(model, data, function(err, id) {
|
||||
if (err) return process.nextTick(function() { cb(err); });
|
||||
|
|
|
@ -350,6 +350,34 @@ describe('Memory connector', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should successfully extract 3 users with inq', function (done) {
|
||||
User.find({
|
||||
where: {
|
||||
seq: {
|
||||
inq: [0, 1, 5]
|
||||
}
|
||||
}
|
||||
}, function (err, users) {
|
||||
should.not.exist(err);
|
||||
users.length.should.be.equal(3);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should successfully extract 4 users with nin', function (done) {
|
||||
User.find({
|
||||
where: {
|
||||
seq: {
|
||||
nin: [2, 3]
|
||||
}
|
||||
}
|
||||
}, function (err, users) {
|
||||
should.not.exist(err);
|
||||
users.length.should.be.equal(4);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should count using date string', function(done) {
|
||||
User.count({birthday: {lt: new Date(1990,0).toISOString()}},
|
||||
function(err, count) {
|
||||
|
|
Loading…
Reference in New Issue