Skip to content

Commit

Permalink
Add neq operator (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidPayne-Woodscamp committed Mar 3, 2020
1 parent 71a9c7a commit 1be6853
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -146,7 +146,7 @@ A filter parameter has the following format:
A `propertyReference` is either simply a property name like `firstName` or a reference to a relation's property like
`children.age` (`children` is the name of the relation).

`filter` is one of the built-in filters `eq`, `lt`, `lte`, `gt`, `gte`, `like`, `likeLower` `in`, `notNull` or `isNull`.
`filter` is one of the built-in filters `eq`, `neq`, `lt`, `lte`, `gt`, `gte`, `like`, `likeLower` `in`, `notNull` or `isNull`.
Filter can also be a custom filter registered using the `registerFilter` method.

The following examples explain how filter parameters work. For the examples, assume we have an objection.js model
Expand Down
8 changes: 8 additions & 0 deletions lib/filters.js
Expand Up @@ -3,6 +3,7 @@
module.exports = {
in: inSet,
eq: eq,
neq: neq,
lt: lt,
lte: lte,
gt: gt,
Expand Down Expand Up @@ -40,6 +41,13 @@ function eq(propertyRef, value) {
return basicWhere(propertyRef, '=', value);
}

/**
* @private
*/
function neq(propertyRef, value) {
return basicWhere(propertyRef, '<>', value);
}

/**
* @private
*/
Expand Down
23 changes: 23 additions & 0 deletions tests/test.js
Expand Up @@ -85,6 +85,29 @@ describe('integration tests', () => {
});
});

describe('neq', () => {
it('should filter using <> operator', () => {
return objectionFind(Person)
.build({
'firstName:neq': 'F01'
})
.then(results => {
// Everything except 'F01'
expect(results.map(result => result.firstName).sort()).to.eql([
'F00',
'F02',
'F03',
'F04',
'F05',
'F06',
'F07',
'F08',
'F09'
]);
});
})
});

describe('lt', function() {
it('should filter using < operator', function() {
return objectionFind(Person)
Expand Down

0 comments on commit 1be6853

Please sign in to comment.