Browse Source

Add raw statement for special handling like postgres operators

pull/2/head
Jose Varela 7 years ago
committed by joselcvarela
parent
commit
0f93490366
  1. 5
      index.js
  2. 12
      test.js

5
index.js

@ -25,6 +25,8 @@ var functionOperatorMap = {
AND_NOTIN: 'andWhereNotIn',
AND_ISNULL: 'andWhereNull',
AND_NOTNULL: 'andWhereNotNull',
/* ---- */
RAW: 'whereRaw'
};
var aliases = {
@ -62,7 +64,8 @@ function addCondition (q, field, val) {
val = [ 'AND', field ].concat(val);
}
}
return q[functionOperatorMap[val[0]]].apply(q, val.slice(1));
var args = val[0] === 'RAW' ? [ '"'+val[1]+'" ' + val[2] ] : val.slice(1)
return q[functionOperatorMap[val[0]]].apply(q, args);
}

12
test.js

@ -72,6 +72,11 @@ var conditions= [
input:{ f1: ['NOTIN', [ 50, 60 ] ], f2: 20, f3: 30 },
output: 'select * where ("f1" not in (50, 60) and "f2" = 20 and "f3" = 30)'
},
{
name: 'handle simple and condition with raw statement',
input: { f1: { $raw: '@> ANY(ARRAY(1,2,3))' }, f2: 20 },
output: 'select * where ("f1" @> ANY(ARRAY(1,2,3)) and "f2" = 20)'
},
/* -----------Tests for or conditions---------- */
{
name: 'handle simple or condition',
@ -125,9 +130,14 @@ var conditions= [
},
{
name: 'handle simple or condition with nin statement :MongoQuery',
input:[ { f1: {$nin:[ 50, 60 ]} }, { f2: 20 }, { f3: 30 } ],
input:[ { f1: { $nin: [ 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 raw statement',
input: [ { f1: { $raw: '@> ANY(ARRAY(1,2,3))' } }, { f2: 20 } ],
output: 'select * where (("f1" @> ANY(ARRAY(1,2,3))) or ("f2" = 20))'
},
];

Loading…
Cancel
Save