Simple conversion from REST filter operators to SQL WHERE clauses
$ npm install rest-filter-to-sql
const filter = require('rest-filter-to-sql');
let obj = {
name: 'Bill Murray',
rated: { $gt: 90},
movies: { $in: ['Groundhog Day', 'Lost In Translation']}
}
let sql = filter.parse(obj)
console.log(sql)
// WHERE name = 'Bill Murray'
// AND rated > 90
// AND movies IN ('Groundhog Day','Lost In Translation')
These expect an array
as the object value.
- $or OR
- $and AND
- $in IN
- $not NOT IN
These expect a number
as the object value.
- $gt >
- $gte >=
- $lt <
- $lte <=
These expect a string
as the object value.
- $contains
- $containsi (case insensitive)
- $startsWith
- $startsWithi (case insensitive)
- $endsWith
- $endsWithi (case insensitive)