-3

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
stach
  • 23
  • 3

1 Answers1

1

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'] ]
      })
Shahar Hadas
  • 2,641
  • 1
  • 27
  • 29