Add neq operator support for memory connector
See https://github.com/strongloop/loopback-datasource-juggler/issues/265
This commit is contained in:
parent
7698f0f08b
commit
e9f00fbd8b
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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 = [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue