Skip to content

Commit

Permalink
Update readme with conditionMapper documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
perfectmak committed Jul 17, 2019
1 parent dd2b750 commit b3352c9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,29 @@ const query = knexFlexFilter(

Set to `true` if you want to use insensitive-case searches when using `contains` or `starts_with` filters. Defaults to false.

### conditionMapper
Useful to transform/change the default operator or condition that a
particular filter is being evaluated against. `conditionMapper` receives the column name, the condition being evaluated and the default/normal value that should returned for the condition.

For example, here we change the `contains` condition to use json containment operator `@>`:

```javascript
import { knexFlexFilter, CONTAINS } from 'knex-flex-filter';
...

const opts = {
conditionMapper: (column, condition, defaultValue) => {
if (condition === CONTAINS) {
return '@> ?';
}

return defaultValue;
}
}

knexFlexFilter(baseQuery, where, opts).then(console.log);
```

## Contributing

Make sure all the tests pass before sending a PR. To run the test suite, run `yarn test`. Please note that the codebase is using `dotenv` package to connect to a test db, so, to connect to your own, add a `.env` file inside the `tests` folder with the following structure:
Expand Down
2 changes: 1 addition & 1 deletion tests/knex-flex-filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require('./helpers/database');


describe('knex-flex-filter', () => {
let castFn;
let castFn;

beforeEach(async (done) => {
await seedsFn(knex);
Expand Down

0 comments on commit b3352c9

Please sign in to comment.