SELECT `code_id`, `credits` FROM `promotion_codes` WHERE `code`=? AND CURDATE() BETWEEN `start_date` AND `expiry_date` limit 1
是否有任何解决方案可以在续集中执行相同的上述查询或在sequelize中执行CURDATE()函数的替代?
答案 0 :(得分:2)
PromotionCodes.findAll({
where: {
code: code,
start_date: { lt: Sequelize.fn('CURRDATE') },
expiry_date: { lt: Sequelize.fn('CURRDATE') }
},
limit: 1
});
这不是完全相同的查询,因为它生成start_date < CURRDATE() AND end_date > CURRDATE()
,但它应该做你想要的