mirror of
https://github.com/harish2704/knex-json-query.git
synced 2026-09-10 04:41:07 +00:00
Add raw statement for special handling like postgres operators
This commit is contained in:
committed by
joselcvarela
parent
91301c839a
commit
0f93490366
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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))'
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user