Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional queries #1068

Closed
fsebbah opened this issue Nov 23, 2015 · 3 comments
Closed

Conditional queries #1068

fsebbah opened this issue Nov 23, 2015 · 3 comments
Labels

Comments

@fsebbah
Copy link

fsebbah commented Nov 23, 2015

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

@rhys-vdw
Copy link
Member

QueryBuilder#modify

knex('table').select('col_a').modify(function (qb) {
  if (bValue) {
    qb.where('col_b', bValue);
  }
}).then(...

@fsebbah
Copy link
Author

fsebbah commented Nov 23, 2015

it's perfect for me. Is there a forum ?
Thanks,
Franck

@elhigu
Copy link
Member

elhigu commented Dec 17, 2015

As far as I know github issues is the only forum for knex.

@elhigu elhigu closed this as completed Dec 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants