soar
soar
DTDrizzle Team
Created by soar on 6/12/2023 in #help
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);
}
});
knex('questions')
.select('question', 'correct', 'incorrect')
.modify(function(queryBuilder) {
if (req.query.param) {
queryBuilder.where('somecolumn', req.query.param);
}
});
5 replies