Hi,
I don't know if this request exists. But I search a way to build a select query with conditional arguments.
Sample:
knex('mytable')
.select('champ1','champ2','champ3')
.where ('champ1','=',val1)
.andWhere ('champ2','=',val2)
.then{function(rows,err){
})
etc...
But if champ2 is empty or don't fill the condition
I must duplicate the code without the andWhere
knex('mytable')
.select('champ1','champ2','champ3')
.where ('champ1','=',val1)
.then{function(rows,err){
etc...
})
If i give as value2 :'*', the query turn off.
If you a reference, thanks.
Franck
knex('table').select('col_a').modify(function (qb) {
if (bValue) {
qb.where('col_b', bValue);
}
}).then(...
it's perfect for me. Is there a forum ?
Thanks,
Franck
As far as I know github issues is the only forum for knex.
Most helpful comment
QueryBuilder#modify