我正在使用 Sequelize.js 处理 MySQL 中的数据,我想找到一个“updatedAt”在特定日期之后的数据,我尝试了以下代码:
const post = await Posts.findByPk(ctx.request.query.id);
const {updatedAt} = post;
const prev = await Posts.findOne({
where: {
updatedAt: {
[Op.gt]: updatedAt
}
},
attributes: ['id', 'title']
});
似乎 [Op.gt] 不起作用,Sequelize.js 返回了一个带有随机日期的数据。
那么,如何在 Sequelize.js 中的特定日期之后选择数据?
谢谢你的帮助!
最佳答案
我搞砸了,代码是对的,Sequelize 返回了正确的数据,我只需要告诉 Sequelize 顺序:
const post = await Posts.findByPk(ctx.request.query.id);
const {updatedAt} = post;
const prev = await Posts.findOne({
where: {
updatedAt: {
[Op.gt]: updatedAt
}
},
order: [['updatedAt', 'ASC']],
attributes: ['id', 'title']
});
关于sequelize.js - 如何在 Sequelize.js 中的特定日期之后选择数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60405460/