diff --git a/index.js b/index.js index 2b37e46..7dee2d5 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,8 @@ var functionOperatorMap = { BETWEEN: 'whereBetween', IN: 'whereIn', + NIN: 'whereNotIn', + NOTIN: 'whereNotIn', ISNULL: 'whereNull', NOTNULL: 'whereNotNull', /* ---- */ @@ -14,11 +16,13 @@ var functionOperatorMap = { /* ---- */ OR_BETWEEN: 'orWhereBetween', OR_IN: 'orWhereIn', + OR_NOTIN: 'orWhereNotIn', OR_ISNULL: 'orWhereNull', IR_NOTNULL: 'orWhereNotNull', /* ---- */ AND_BETWEEN: 'andWhereBetween', AND_IN: 'andWhereIn', + AND_NOTIN: 'andWhereNotIn', AND_ISNULL: 'andWhereNull', AND_NOTNULL: 'andWhereNotNull', }; diff --git a/test.js b/test.js index 6ab7fc3..730bb04 100644 --- a/test.js +++ b/test.js @@ -6,7 +6,7 @@ require('simple-mocha'); var conditions= [ - /* -----------Tests for and conditoins---------- */ + /* -----------Tests for and conditions---------- */ { name: 'handle simple and conditions', input:{ f1: 10, f2: 20, f3: 30 }, @@ -42,6 +42,11 @@ var conditions= [ input:{ f1: ['IN', [10,50]], f2: [ '<', 20 ], 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', 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 }, 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', input:[ { f1: 10 }, { f2: 20 }, { f3: 30 } ], @@ -103,11 +113,21 @@ var conditions= [ input:[ { f1: ['IN',[ 50, 60 ]] }, { f2: 20 }, { 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', input:[ { f1: {$in:[ 50, 60 ]} }, { f2: 20 }, { 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))' + }, ];