Add neq operator support for memory connector

See https://github.com/strongloop/loopback-datasource-juggler/issues/265
This commit is contained in:
Raymond Feng 2014-08-29 08:45:45 -07:00
parent 7698f0f08b
commit e9f00fbd8b
2 changed files with 30 additions and 2 deletions

View File

@ -406,7 +406,7 @@ function applyFilter(filter) {
if (typeof value === 'string' && (example instanceof RegExp)) { if (typeof value === 'string' && (example instanceof RegExp)) {
return value.match(example); return value.match(example);
} }
if (example === undefined || value === undefined) { if (example === undefined) {
return undefined; return undefined;
} }
if (typeof example === 'object') { if (typeof example === 'object') {
@ -425,6 +425,10 @@ function applyFilter(filter) {
return false; return false;
} }
if (example.neq) {
return compare(example.neq, value) !== 0;
}
if (example.like || example.nlike) { if (example.like || example.nlike) {
var like = example.like || example.nlike; var like = example.like || example.nlike;
@ -445,7 +449,7 @@ function applyFilter(filter) {
} }
} }
// not strict equality // not strict equality
return (example !== null ? example.toString() : example) == (value !== null ? value.toString() : value); return (example !== null ? example.toString() : example) == (value != null ? value.toString() : value);
} }
/** /**

View File

@ -199,6 +199,30 @@ describe('Memory connector', function () {
}); });
}); });
it('should support neq operator for number', function (done) {
User.find({where: {order: {neq: 6}}}, function (err, users) {
should.not.exist(err);
users.length.should.be.equal(5);
for (var i = 0; i < users.length; i++) {
users[i].order.should.not.be.equal(6);
}
done();
});
});
it('should support neq operator for string', function (done) {
User.find({where: {role: {neq: 'lead'}}}, function (err, users) {
should.not.exist(err);
users.length.should.be.equal(4);
for (var i = 0; i < users.length; i++) {
if (users[i].role) {
users[i].role.not.be.equal('lead');
}
}
done();
});
});
function seed(done) { function seed(done) {
var beatles = [ var beatles = [
{ {