1.3.0 • Published 9 years ago
wql v1.3.0
wql
wql is a WHERE clause generator for WQL queries using MongoDB syntax.
Installation
npm i --save wqlExamples
import wql from 'wql';Simple matching
wql({
propString: 'str',
propLike: { $like: 'foo' },
propNumber: { $gt: 1 },
propBool: true,
});output
propString = "str" AND propLike like "%foo%" AND propNumber > 1 AND propBool = trueArrays (in)
wql({
foo: { $in: [1, 2, 5, 10] },
});output
(foo = 1 OR foo = 2 OR foo = 5 OR foo = 10)Arrays (not in)
wql({
foo: { $nin: [1, 2, 5, 10] },
});output
(foo != 1 AND foo != 2 AND foo != 5 AND foo != 10)AND
wql({
$and: [
{ foo1: 1, bar1: 'a' },
{ foo2: 2, bar2: 'b' },
],
});output
(foo1 = 1 AND bar1 = "a") AND (foo2 = 2 AND bar2 = "b")OR
wql({
$or: [
{ foo1: 1, bar1: 'a' },
{ foo2: 2, bar2: 'b' },
],
});output
(foo1 = 1 AND bar1 = "a") OR (foo2 = 2 AND bar2 = "b")Nested queries
wql({
$and: [
{ foo1: 1, bar1: 'a' },
{
$or: [
{ a: 1, c: 1 },
{ b: 2, c: 1 },
],
},
],
};output
(foo1 = 1 AND bar1 = "a") AND ((a = 1 AND c = 1) OR (b = 2 AND c = 1))Supported operators
$ne$eq$gte$lte$gt$lt$in$nin$like$startsWith
MIT License
Copyright (c) 2016 Łukasz Sentkiewicz