Skip to content

Declarative filtering for `knex.js` based on the Loopback Where Filter.

License

Notifications You must be signed in to change notification settings

joostvunderink/knex-filter-loopback

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

knex-filter-loopback

Declarative filtering for knex.js based on the Loopback Where Filter. This module has been inspired by and based on Constantin Titarenko's knex filter module.

Build Status Coverage Status

NPM

Installation

npm i knex-filter-loopback --save

Usage

var whereFilter = require('knex-filter-loopback').whereFilter;

knex('tablename')
	.where(whereFilter({
		a: 'b',
		c: { '>': 12 },
		d: { 'in': [1, 2, 3] },
		e: null,
		not: { f: null },
		or: [
			{ k: 1 },
			{ k: 5 },
			{ m: { 'like': '%Bob%' },
		],
	}))
	.then(console.log);

Motivation

Imagine you have page with filterable table, user changes state of your filter controls and presses "apply": you need to pass that filter to backend to obtain filtered set from it. I'm sure you had such case. Was it tedious to walk trough query string and imperatively build your query using knex.js? Forget it, you can now provide filter object from your frontend to your backend and apply it with no effort!

License

MIT

About

Declarative filtering for `knex.js` based on the Loopback Where Filter.

Resources

License

Stars

Watchers

Forks

Packages

No packages published