续集如何查找具有多个where子句和时间戳的行>现在()

2022-01-19 00:00:00 node.js javascript sequelize.js

如何使用 Sequelize 做到这一点?

How do I do this with Sequelize?

SELECT FROM sessions WHERE user_id = ? AND token = ? AND expires > NOW()

这是我想要做的(假设 Session 是一个 Sequelize 模型):

Here's what I'm trying to do (assume Session is a Sequelize model):

Session.find({
    where: {
        user_id: someNumber,
        token: someString,
        //expires > NOW() (how do I do this?)
    }
}).on('success', function (s) { /* things and stuff */ });

谢谢!

推荐答案

你有没有尝试在sequelize中使用finders的数组表示法?

did you try to use the array notation of finders in sequelize?

Session.find({
  where: ['user_id=? and token=? and expires > NOW()', someNumber, someString]
}).on('success', function (s) { /* things and stuff */ });

您可以查看此页面:http://sequelizejs.com/?active=find-objects#find-对象

希望这可行.否则这是一个错误:D

Hope this works. Otherwise it's a bug :D

相关文章