rest-filter-to-sql

1.0.1 • Public • Published

rest-filter-to-sql

Simple conversion from REST filter operators to SQL WHERE clauses

Installation

$ npm install rest-filter-to-sql

Usage

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')

Supported operators

Logical:

These expect an array as the object value.

  • $or OR
  • $and AND
  • $in IN
  • $not NOT IN

Comparison:

These expect a number as the object value.

  • $gt >
  • $gte >=
  • $lt <
  • $lte <=

String:

These expect a string as the object value.

  • $contains
  • $containsi (case insensitive)
  • $startsWith
  • $startsWithi (case insensitive)
  • $endsWith
  • $endsWithi (case insensitive)

/rest-filter-to-sql/

    Package Sidebar

    Install

    npm i rest-filter-to-sql

    Weekly Downloads

    1

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    7.81 kB

    Total Files

    4

    Last publish

    Collaborators

    • martymc