I am using Sequelize along with PostgreSQL in managing my database.
I would like to perform a case insensitive search query. When I googled it up, some people said that I can use "iLike" operator to do so. I tried to implement this way:
var getRadiosByGenre = function(Radio,Genre,genreName){
Genre.findOne({where:{name: { $iLike: genreName}}})}
where genreName is a string. But, I keep getting this error:
Error: Invalid value { '$iLike': 'art' }
Does anyone know the correct way of using iLike with sequelize? Thanks mates(s). :)
You should use Sequelize.Op
:
var getRadiosByGenre = function(Radio,Genre,genreName) {
Genre.findOne({
where: {
name: {
[Sequelize.Op.iLike]: genreName
}
}
});
}
Don't forget to add %
before or after your genreName
if you want to make a partial query.
See the docs here >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With