0

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.

Sumit M Asok
  • 2,950
  • 7
  • 29
  • 38

2 Answers2

1
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)
ferhatelmas
  • 3,818
  • 1
  • 21
  • 25
0

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)

Sumit M Asok
  • 2,950
  • 7
  • 29
  • 38