在phpMyAdmin上执行此操作会给我一个记录。
SELECT * FROM `banners` WHERE region_id = 1 AND status= 'approved' and approved_date = CURRENT_DATE;
但是我尝试使用这样的序列化来实现相同的目的
const banners = await db.banners.findAll({
where: {
region_id: id,
status: "approved",
approved_date: new Date()
}
});
当我跟踪查询时
选择id
,path
,expire_date
,status
,fee
,notes
,approved_date
,{{1} },
region_id
中restaurant_id
的{{1}},is_paid
,createdAt
,updatedAt
banners
。banners
= 1 AND banners
。region_id
='approved'AND
banners
。status
='2018-10-11 17:29:31';
我看到的问题是banners
列数据类型是日期和比较approved_date
日期和时间。 sequlize中与CURRENT_DATE类似的关键字是什么
答案 0 :(得分:2)
如果您想直接将字符串传递给WHERE
条件,则可以使用sequelize.literal
:
const banners = await db.banners.findAll({
where: {
$and: [
{
region_id: id,
status: "approved"
}
],
sequelize.where(
sequelize.fn('DATE', sequelize.col('approved_date')),
sequelize.literal('CURRENT_DATE')
)
}
});
答案 1 :(得分:0)
此答案也有效!
const banners = await db.banners.findAll({
where: {
region_id: id,
status: "approved",
approved_date: db.Sequelize.fn('CURRENT_DATE')
}
});