英文:
Create Between Query using gorethink
问题
如何将这个rethinkdb查询转换为gorethink查询:
r.DB("arkinventory").Table("reportsdata").Between(r.Time(2012, 8, 13, 23, 32, 49, 923000000, "Z"), r.Time(2013, 8, 13, 23, 32, 49, 923000000, "Z"), r.BetweenOpts{Index: "updated_at"}).Run(session)
我尝试了以下代码:
r.DB("arkinventory").Table("reportsdata").Filter(func(row r.Term) r.Term {
return row.Between(r.Time(2014, 8, 12, 0, 0, 0, "Z"), r.Time(2014, 8, 12, 0, 0, 0, "Z"), r.BetweenOpts{Index: "updated_at"})
}).Run(session)
你可以尝试使用 row.Date
或 row.ToEpochTime
来获取结果。如果还无法得到结果,请帮助我完善这个gorethink查询。
英文:
How to convert this rethinkdb query into gorethink query
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"})
I tried
.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
But yet not able to get the result. Please help me formulate this query in gorethink.
答案1
得分: 1
t := r.Table("yourTable")
t.Between(from, to,
r.BetweenOpts{Index: "updated_at"}
).OrderBy(r.OrderByOpts{Index: r.Desc("updated_at")}).Run(dbs)
这里的from
和to
取决于你保存这些值的方式,例如int64、string、time等。根据之前的示例,r.Time(args)
应该可以工作。
如果索引不存在,可以通过以下方式创建索引:
t.IndexCreate("updated_at").Exec(dbs)
t.IndexWait().RunWrite(dbs)
英文:
t := r.Table("yourTable")
t.Between(from, to,
r.BetweenOpts{Index: "updated_at"}
).OrderBy(r.OrderByOpts{Index: r.Desc("updated_at")}).Run(dbs)
Here, from
and to
depends how you save these values i.e int64, string, time, etc. According to previous example r.Time(args)
should work.
If nonexist, create index via:
t.IndexCreate("updated_at").Exec(dbs)
t.IndexWait().RunWrite(dbs)
答案2
得分: 0
根据dancannon在gitter频道上的回复,我们应该在日期上使用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)
英文:
As per dancannon's response on gitter channel https://gitter.im/dancannon/gorethink
We should use During instead of Between for Dates.
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论