简体   繁体   English

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

[英]Sequelize how to find rows with multiple where clauses and timestamp > NOW()

How do I do this with Sequelize? 我如何用Sequelize做到这一点?

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

Here's what I'm trying to do (assume Session is a Sequelize model): 这是我正在尝试做的事情(假设Session是Sequelize模型):

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

Thanks! 谢谢!

did you try to use the array notation of finders in sequelize? 你试图在sequelize中使用finders的数组符号吗?

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

You can checkout this page: http://sequelizejs.com/?active=find-objects#find-objects 您可以查看此页面: http//sequelizejs.com/? active = find-objects#find- objects

Hope this works. 希望这有效。 Otherwise it's a bug :D 否则这是一个错误:D

Please note that as of this posting and the most recent version of sequelize, the above answers are out of date. 请注意,截至本帖子和最新版本的续集,上述答案已过时。 I am posting the solution that I got working in hopes of saving someone some time. 我发布了我工作的解决方案,希望能节省一些时间。

filters["State"] = {$and: [filters["State"], {$not: this.filterSBM()}] };

Note the $ and array inside the JSON object and lack of ? 注意JSON对象里面的$和数组缺少? token replacement. 令牌替换。

Or put in a more general way, since that might help someone wrap their head around it: 或者以更一般的方式,因为这可能有助于有人围绕它:

{ $and: [{"Key1": "Value1"}, {"Key2": "Value2"}] }

Another method: 另一种方法:

Session.find({
  where: {
    user_id: someNumber,
    token: someString,
    expires: {
      $gt: (new Date())
    }
  }
}).on('success', function (s) { /* things and stuff */ });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM