console.log(req.query)
[
{ ref: [ 'COLUMNNAME1' ] },
'=',
{ val: 'your value1' } ,
and,
{ ref: [ 'COLUMNNAME2' ] },
'=',
{ val: 'your value2' } ,
.......
]
[
{
func: 'toupper',
args: [ { ref: [ 'COLUMN1' ] } ]
},
'like',
{ val: '%YOUR VALUE1%' },
and,
{
func: 'toupper',
args: [ { ref: [ 'COLUMN2' ] } ]
},
'like',
{ val: '%YOUR VALUE2%' },
.......
]
this.before ('READ', '*' ,async (req)=>{
//console.log(req);
console.log("before searching");
console.log(req.query.SELECT.where);
let conditions =req.query.SELECT.where;
/*console.log(conditions[0].ref);
console.log(conditions[1]);
console.log(conditions[2].val);
*/
//req.query.SELECT.where[1] = 'LIKE';
//req.query.SELECT.where[2].val = `%${conditions[2].val}%`;
//req.query.SELECT.where.push('and');
//req.query.SELECT.where.push({ func: 'contains', args: [ { ref: [ 'KEYWORD' ] }, { val: '20' } ] });
var newCondition = [];
if (conditions){
conditions.forEach((condition,index) => {
var scol ='';
var sval = '';
var sOperator = '';
if(condition==='and' || condition==='or'||condition==='('||condition===')'
|| condition.func !=undefined
){
newCondition.push(condition);
}
if(condition.ref!=undefined){
//console.log(index);
scol=condition.ref[0];
sOperator=conditions[index+1];
sval=conditions[index+2].val;
//newCondition.push({ func: 'contains', args: [ { ref: [ scol ] }, { val: sval } ] });
if(sOperator==='='){
newCondition.push({ func:'toupper', args:[{ref: [ scol ] }]},'like',{ val: `%${sval.toUpperCase()}%` });
}else{
newCondition.push({ ref: [ scol ] },sOperator,{ val: sval });
}
//newCondition.push(`${scol} like '%${sval}%'`);
}
});
}
//overwrite the condition
//req.query.SELECT.where = newCondition;
if(newCondition&& newCondition.length>0){
req.query.SELECT.where = newCondition;
}
console.log(req.query.SELECT.where);
})
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
40 | |
25 | |
17 | |
14 | |
8 | |
7 | |
7 | |
7 | |
6 | |
6 |