Dynamic where query

With a relational query, is there a way to change the where query based on user input?

In Knex.js, we could do something like this:

knex('questions')
    .select('question', 'correct', 'incorrect')
    .modify(function(queryBuilder) {
        if (req.query.param) {
            queryBuilder.where('somecolumn', req.query.param);
        }
    });
Was this page helpful?