简体   繁体   English

将 sql 查询转换为 sequelize 查询

[英]convert sql query to sequelize query

how to convert this to sequelize query.如何将其转换为续集查询。 I've tried using between but it does not have the same result.我试过使用 between,但结果不一样。 I dont think between is the solution, how about lte and gte?我不认为之间是解决方案,lte和gte怎么样? Thank you谢谢

using between之间使用

where: {
  createdAt: {
    [Op.between]: ["2018-07-08T14:06:48.000Z", "2019-10-08T22:33:54.000Z"]
  }
}

convert this sql to sequelize query将此 sql 转换为续集查询

SELECT * FROM testtable WHERE createdAt >= '2020-06-15 00:00:00' AND createdAt <= '2020-06-18 00:00:00' 

You can include the same property more than once within the where and this would work like AND in your SQL query:您可以在where多次包含相同的属性,这将像您的 SQL 查询中的AND一样工作:

where: {
    createdAt: { [Op.gte]: '2020-06-15' },
    createdAt: { [Op.lte]: '2020-06-18' }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM