Mau*_*ido 2 mysql node.js sequelize.js
我目前有这个代码:
\nEvento.findAll({\n where: db.sequelize.where(db.sequelize.fn('MONTH', db.sequelize.col('start_date')), req.body.month),\n order: ['start_date'],\n attributes: ['id', 'description', 'start_date', 'end_date', 'picture', 'status', 'place', 'text'],\n include: [{\n model: TypeEvent\n }]\n}).then(events => {\n if (events) {\n res.status(200).send({\n events\n });\n } else {\n res.status(400).send({\n message: "without events"\n });\n }\n});\nRun Code Online (Sandbox Code Playgroud)\n但我也需要咨询今年的事情,我不知道该怎么做,我已经尝试了所有方法,但我无法得到答案。
\n我想要的 SQL 查询:
\nSELECT .... FROM ... WHERE MONTH(start_date)=5 AND YEAR(start_date)=2021 ORDER BY ..\nRun Code Online (Sandbox Code Playgroud)\n请帮助我\xc2\xa1\xc2\xa1\xc2\xa1\xc2\xa1
\nEvento.findAll({
where: {
[Op.and]: [
Sequelize.where(Sequelize.fn('MONTH', Sequelize.col('start_date')), req.body.month),
Sequelize.where(Sequelize.fn('YEAR', Sequelize.col('start_date')), req.body.year),
],
},
order: ['start_date'],
attributes: ['id', 'description', 'start_date', 'end_date', 'picture', 'status', 'place', 'text'],
include: [
{
model: TypeEvent,
},
],
}).then((events) => {
if (events) {
res.status(200).send({
events,
});
} else {
res.status(400).send({
message: 'without events',
});
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3521 次 |
| 最近记录: |