RethinkDB Thinky - 1 小时内的行

RethinkDB Thinky - rows within 1 hour

r.db('dbname').table('urls').filter(function(url) {
  return url("expires_at").date().eq(r.now().date())
    .and(url("expires_at").hours().eq(r.now().hours().sub(1)))
});

我正在尝试使用 thinky ORM 为 node.js

编写等效查询

我从未使用过 Thinky,但根据文档,您应该创建模型并对其进行查询。

1) 创建模型。我不知道你在 Rethink 中存储了什么文件。但是像这样:

var thinky = require('thinky')();
var type   = thinky.type;

// Create a model
var Urls = thinky.createModel("urls", {
  id: String,
  expires_at: Date
  // another fields if needed
}); 

2) 查询:

不知道 Thinky 中过滤器的实际语法,但大概是这样的:

Urls.filter(function(url) {
     return url("expires_at").date().eq(r.now().date())
           .and(url("expires_at").hours().eq(r.now().hours().sub(1)))
}).then(function(result) {
     // result is an array of instances of `Urls `
});