Browse Source

Merge pull request #1 from joselcvarela/not-in-statement

Add 'where not in' statement
pull/2/head
Harish K 7 years ago
committed by GitHub
parent
commit
91301c839a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      index.js
  2. 24
      test.js

4
index.js

@ -4,6 +4,8 @@
var functionOperatorMap = { var functionOperatorMap = {
BETWEEN: 'whereBetween', BETWEEN: 'whereBetween',
IN: 'whereIn', IN: 'whereIn',
NIN: 'whereNotIn',
NOTIN: 'whereNotIn',
ISNULL: 'whereNull', ISNULL: 'whereNull',
NOTNULL: 'whereNotNull', NOTNULL: 'whereNotNull',
/* ---- */ /* ---- */
@ -14,11 +16,13 @@ var functionOperatorMap = {
/* ---- */ /* ---- */
OR_BETWEEN: 'orWhereBetween', OR_BETWEEN: 'orWhereBetween',
OR_IN: 'orWhereIn', OR_IN: 'orWhereIn',
OR_NOTIN: 'orWhereNotIn',
OR_ISNULL: 'orWhereNull', OR_ISNULL: 'orWhereNull',
IR_NOTNULL: 'orWhereNotNull', IR_NOTNULL: 'orWhereNotNull',
/* ---- */ /* ---- */
AND_BETWEEN: 'andWhereBetween', AND_BETWEEN: 'andWhereBetween',
AND_IN: 'andWhereIn', AND_IN: 'andWhereIn',
AND_NOTIN: 'andWhereNotIn',
AND_ISNULL: 'andWhereNull', AND_ISNULL: 'andWhereNull',
AND_NOTNULL: 'andWhereNotNull', AND_NOTNULL: 'andWhereNotNull',
}; };

24
test.js

@ -6,7 +6,7 @@ require('simple-mocha');
var conditions= [ var conditions= [
/* -----------Tests for and conditoins---------- */
/* -----------Tests for and conditions---------- */
{ {
name: 'handle simple and conditions', name: 'handle simple and conditions',
input:{ f1: 10, f2: 20, f3: 30 }, input:{ f1: 10, f2: 20, f3: 30 },
@ -42,6 +42,11 @@ var conditions= [
input:{ f1: ['IN', [10,50]], f2: [ '<', 20 ], f3: 30 }, input:{ f1: ['IN', [10,50]], f2: [ '<', 20 ], f3: 30 },
output: 'select * where ("f1" in (10, 50) and "f2" < 20 and "f3" = 30)' output: 'select * where ("f1" in (10, 50) and "f2" < 20 and "f3" = 30)'
}, },
{
name: 'handle basic operators :: notin',
input:{ f1: ['NOTIN', [10,50]], f2: [ '<', 20 ], f3: 30 },
output: 'select * where ("f1" not in (10, 50) and "f2" < 20 and "f3" = 30)'
},
{ {
name: 'handle multiple conditions in one field', name: 'handle multiple conditions in one field',
input:{ f1: [ [ 'LIKE', 20 ], 21, [ 'AND_BETWEEN', [ 40, 45 ] ] ], f2: 20, f3: 30 }, input:{ f1: [ [ 'LIKE', 20 ], 21, [ 'AND_BETWEEN', [ 40, 45 ] ] ], f2: 20, f3: 30 },
@ -62,7 +67,12 @@ var conditions= [
input:{ f1: ['IN', [ 50, 60 ] ], f2: 20, f3: 30 }, input:{ f1: ['IN', [ 50, 60 ] ], f2: 20, f3: 30 },
output: 'select * where ("f1" in (50, 60) and "f2" = 20 and "f3" = 30)' output: 'select * where ("f1" in (50, 60) and "f2" = 20 and "f3" = 30)'
}, },
/* -----------Tests for or conditoins---------- */
{
name: 'handle simple and condition with not in statement',
input:{ f1: ['NOTIN', [ 50, 60 ] ], f2: 20, f3: 30 },
output: 'select * where ("f1" not in (50, 60) and "f2" = 20 and "f3" = 30)'
},
/* -----------Tests for or conditions---------- */
{ {
name: 'handle simple or condition', name: 'handle simple or condition',
input:[ { f1: 10 }, { f2: 20 }, { f3: 30 } ], input:[ { f1: 10 }, { f2: 20 }, { f3: 30 } ],
@ -103,11 +113,21 @@ var conditions= [
input:[ { f1: ['IN',[ 50, 60 ]] }, { f2: 20 }, { f3: 30 } ], input:[ { f1: ['IN',[ 50, 60 ]] }, { f2: 20 }, { f3: 30 } ],
output: 'select * where (("f1" in (50, 60)) or ("f2" = 20) or ("f3" = 30))' output: 'select * where (("f1" in (50, 60)) or ("f2" = 20) or ("f3" = 30))'
}, },
{
name: 'handle simple or condition with not in statement',
input:[ { f1: ['NOTIN',[ 50, 60 ]] }, { f2: 20 }, { f3: 30 } ],
output: 'select * where (("f1" not in (50, 60)) or ("f2" = 20) or ("f3" = 30))'
},
{ {
name: 'handle simple or condition with in statement :MongoQuery', name: 'handle simple or condition with in statement :MongoQuery',
input:[ { f1: {$in:[ 50, 60 ]} }, { f2: 20 }, { f3: 30 } ], input:[ { f1: {$in:[ 50, 60 ]} }, { f2: 20 }, { f3: 30 } ],
output: 'select * where (("f1" in (50, 60)) or ("f2" = 20) or ("f3" = 30))' output: 'select * where (("f1" in (50, 60)) or ("f2" = 20) or ("f3" = 30))'
}, },
{
name: 'handle simple or condition with nin statement :MongoQuery',
input:[ { f1: {$nin:[ 50, 60 ]} }, { f2: 20 }, { f3: 30 } ],
output: 'select * where (("f1" not in (50, 60)) or ("f2" = 20) or ("f3" = 30))'
},
]; ];

Loading…
Cancel
Save