Struggling to translate the query "WHERE (CASE ... THEN ... ELSE ... END) > 0" into sequelize v3.33.
Tried using sequelize.literal('...') without success. Although using "HAVING" is a potential solution, it's not ideal for performance with large datasets, as it can be twice as slow.
This snippet depicts MySQL code that closely resembles my objective.
SELECT
(CASE `a`.`fee` IS NULL
THEN `a.b`.`fee`
ELSE `a`.`fee`
END) AS `_fee`
FROM `a`
WHERE
(CASE `a`.`fee` IS NULL
THEN `a.b`.`fee`
ELSE `a`.`fee`
END) > 0 AND
(created_at > currentDate
AND
created_at < futureDate)
I am aiming to convert this into sequelize. The provided code showcases my progress so far, but I'm stuck on how to implement the case statement.
models.a.findAll({
...
where: {
created_at: { $gt: startDate, $lt: endDate }
}
})
*** Please disregard the reference to created_at, as it is meant purely as an example.