使用 gorethink 在查询之间创建

Create Between Query using gorethink

如何将此 rethinkdb 查询转换为 gorethink 查询

r.db("arkinventory").table("reportsdata").between(new Date("2012-08-13T23:32:49.923Z"), new Date("2013-08-13T23:32:49.923Z"), {index: "updated_at"})

我试过了

.Filter(func(row r.Term) r.Term { return row.Between(r.Time(2014, 8, 12, 'Z'), r.Time(2014, 8, 12, 'Z'), r.BetweenOpts{Index: "updated_at"}) }).Run(session)

row.Date row.ToEpochTime

但是还没有得到结果。请帮助我在 gorethink 中制定此查询。

t := r.Table("yourTable")
t.Between(from, to,
    r.BetweenOpts{Index: "updated_at"}
).OrderBy(r.OrderByOpts{Index: r.Desc("updated_at")}).Run(dbs)

此处,fromto 取决于您如何保存这些值,即 int64、字符串、时间等。根据前面的示例,r.Time(args) 应该有效。

如果不存在,通过以下方式创建索引:

t.IndexCreate("updated_at").Exec(dbs)
t.IndexWait().RunWrite(dbs)

根据 dancannon 在 gitter 频道上的回复 https://gitter.im/dancannon/gorethink

我们应该使用 During 而不是 Between 作为日期。

Filter(func(row r.Term) r.Term { return row.Field("updated_at").During(r.Time(2014, 8, 12, 'Z'), r.Time(2014, 8, 12, 'Z')) }).Run(session)