I am new to Node.js, am trying to run a 'And' and 'OR' operator in Sequelize, the MySQL query is this
SELECT * from User WHERE (role = 'INSTRUCTOR') AND ((pix <> null) OR (description <> null)) OEDER BY id DESC
The above MySQL query is what I want to run with Sequelize but it didn't work.
Below is my Sequelize code:
return await models.User.findAll({
where: {role: 'INSTRUCTOR'}, [Op.or]: [{pix: {[Op.ne]: null}}, {description: {[Op.ne]: null,}}], order: [['id', 'DESC']]
})
How can I run that query in Sequelize?
Formatting the code can sometimes help ...
Seems you had a misplaced }
return await models.User.findAll({
where: {
role: { [Op.eq]: 'INSTRUCTOR' },
[Op.or]: [
{ pix: { [Op.ne]: null} },
{ description: { [Op.ne]: null } }
]
},
order: [ ['id', 'DESC'] ]
})