Merge pull request #266 from strongloop/feature/fix-issue-265

Add neq operator support for memory connector
This commit is contained in:
Raymond Feng 2014-09-04 10:30:08 -07:00
commit 9a44d11e8e
2 changed files with 43 additions and 2 deletions

View File

@ -406,9 +406,10 @@ 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') {
// ignore geo near filter // ignore geo near filter
if (example.near) { if (example.near) {
@ -425,6 +426,10 @@ function applyFilter(filter) {
return false; return false;
} }
if ('neq' in example) {
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 +450,8 @@ 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,41 @@ 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();
});
});
it('should support neq operator for null', function (done) {
User.find({where: {role: {neq: null}}}, function (err, users) {
should.not.exist(err);
users.length.should.be.equal(2);
for (var i = 0; i < users.length; i++) {
should.exist(users[i].role);
}
done();
});
});
function seed(done) { function seed(done) {
var beatles = [ var beatles = [
{ {