From 68bdbf750cf061e37a508483e61d6f587c494166 Mon Sep 17 00:00:00 2001 From: "Harish.K" Date: Thu, 16 Feb 2017 18:00:04 +0530 Subject: [PATCH] Added support for isnull and notnull query --- index.js | 25 ++++++++----------------- package.json | 2 +- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index bfbe4ee..b1da3e9 100644 --- a/index.js +++ b/index.js @@ -1,24 +1,11 @@ -var functionOperators = [ - 'BETWEEN', - 'IN', - /* ---- */ - 'OR', - 'AND', - 'EQ', - '=', - /* ---- */ - 'OR_BETWEEN', - 'OR_IN', - /* ---- */ - 'AND_BETWEEN', - 'AND_IN' -]; var functionOperatorMap = { BETWEEN: 'whereBetween', IN: 'whereIn', + ISNULL: 'whereNull', + NOTNULL: 'whereNotNull', /* ---- */ OR: 'orWhere', AND: 'where', @@ -27,9 +14,13 @@ var functionOperatorMap = { /* ---- */ OR_BETWEEN: 'orWhereBetween', OR_IN: 'orWhereIn', + OR_ISNULL: 'orWhereNull', + IR_NOTNULL: 'orWhereNotNull', /* ---- */ AND_BETWEEN: 'andWhereBetween', - AND_IN: 'andWhereIn' + AND_IN: 'andWhereIn', + AND_ISNULL: 'andWhereNull', + AND_NOTNULL: 'andWhereNotNull', }; @@ -43,7 +34,7 @@ function addCondition (q, field, val) { if (!Array.isArray(val)) { val = ['AND', field, val ]; - } else if (functionOperators.indexOf(val[0]) !== -1) { + } else if (functionOperatorMap.hasOwnProperty( val[0] ) ) { val = [ val[0], field ].concat(val.slice(1)); } else { val = [ 'AND', field ].concat(val); diff --git a/package.json b/package.json index c19697b..392c16b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "knex-json-query", - "version": "0.0.3", + "version": "0.0.4", "description": "A high-level utility which will will generate Knex query from a single JSON object.", "main": "index.js", "scripts": {