Add raw statement for special handling like postgres operators

This commit is contained in:
Jose Varela
2018-11-16 10:24:30 +00:00
committed by joselcvarela
parent 91301c839a
commit 0f93490366
2 changed files with 15 additions and 2 deletions
+4 -1
View File
@@ -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);
}
+10
View File
@@ -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',
@@ -128,6 +133,11 @@ var conditions= [
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))'
},
];