How to select case query in sequelize?
For the people that are still looking for this answer
Model.findAll({ attributes: [[models.sequelize.literal('CASE WHEN "field1" = true THEN 55 ELSE 23 END'), 'field3']]}
or
Model.findAll({ attributes: { include: [[models.sequelize.literal('CASE WHEN "field1" = true THEN 55 ELSE 23 END'), 'field3']]}}
So in my example when field1 is true it will return 55 else 23. This will generate a query like
SELECT CASE WHEN "field1" THEN 55 ELSE 23 END AS "field3" FROM "models"
For more information you can look in the documentationhttp://docs.sequelizejs.com/en/latest/docs/querying/#attributes