如何以sequelize格式转换此mysql查询

时间:2018-06-21 03:04:10

标签: javascript mysql sql node.js sequelize.js

我知道所有基本的序列化操作,但是如何转换带有许多when情况和/或其他情况的复杂查询。在这里,我给出了mysql查询,

select * 
from `timer` 
where 
  email = 'abcd@gmail.com' 
  and o_id = 'CBADCKDSFO2'  
  and (hour > 8 or (hour = 8 and minute > 27))  
  and (
    (case 
      when dom is not null and mon is not null then dom = 21 and mon = 6  
      when dom is not null and mon is null then dom = 21 
      when dom is null and mon is null then CAST(dow as CHAR(50)) like '%ABC%' end) 
    or 
    (dom is null and mon is null and dow is null )
  ) 
  and act = 5 
order by hour, minute;

我尝试了这个。但这有一些问题,

tables.findAll({
    where: {
        email: <email_id>,
        o_id: <o_id>,
        act: 5,
        attributes: { include: [[tables.sequelize.literal('case when dom is not null and mon is not null then dom = 21 and mon = 6  when dom is not null and mon is null then dom = 21 when dom is null and mon is null then CAST(dow as CHAR(50)) like '%ABC%' end')]]},
        hour: {[gt]: 8},
        [Op.or]:{
            {hour: 10},
            {minute: {[gt]: 27}}
        }
    }
});

我需要在不使用原始查询类型的情况下将其转换为sequelize orm格式。请帮我。预先感谢。

0 个答案:

没有答案