Code Monkey home page Code Monkey logo

wql's Introduction

wql

Build Status codecov

wql is a WHERE clause generator for WQL queries using MongoDB syntax.

Installation

npm i --save wql

Examples

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 = true

Arrays (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

wql's People

Contributors

lstkz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.