Support '$or' & '$and' based grouping for queries

This commit is contained in:
2020-02-23 23:01:53 +05:30
parent ae0663d314
commit 53058d58bf
2 changed files with 18 additions and 1 deletions
+6
View File
@@ -38,6 +38,12 @@ var aliases = {
function addCondition (q, field, val) {
if( field === '$or' ){
return q.orWhere( getWhereCondition( val ))
}
if( field === '$and' ){
return q.where( getWhereCondition( val ))
}
if( val.constructor.name === 'Object' ){
delete val.$options;
val = Object.keys(val).map( function(key){
+12 -1
View File
@@ -78,6 +78,12 @@ var conditions= [
output: 'select * where ("f1" @> ANY(ARRAY(1,2,3)) and "f2" = 20)'
},
/* -----------Tests for or conditions---------- */
{
name: 'handle $and grouping',
input:{ f1: 10, f2: 20, f3: 30, $and: [ { f4: 55 }, { f5: 66} ] },
output: 'select * where ("f1" = 10 and "f2" = 20 and "f3" = 30 and (("f4" = 55) or ("f5" = 66)))'
},
/* -----------Tests for or conditoins---------- */
{
name: 'handle simple or condition',
input:[ { f1: 10 }, { f2: 20 }, { f3: 30 } ],
@@ -142,7 +148,12 @@ var conditions= [
name: 'handle simple or condition with conditional array',
input: { f1: [['ILIKE', 'awesome'], ['OR_ILIKE', '%super%'] ] },
output: 'select * where (("f1" ILIKE \'awesome\' or "f1" ILIKE \'%super%\'))'
}
},
{
name: 'handle $or grouping',
input:{ f1: 10, f2: 20, f3: 30, $or: [ { f4: 55 }, { f5: 66} ] },
output: 'select * where ("f1" = 10 and "f2" = 20 and "f3" = 30 or (("f4" = 55) or ("f5" = 66)))'
},
];