Fork me on GitHub
#xtdb
<
2023-04-26
>
mpenet06:04:26

the core2 website/docs disapeared?

mpenet06:04:50

oh but the repo also moved. Ok, big move over to the main thing I suppose

☺️ 2
💯 2
Xiaomin Wang21:04:32

Hi, can’t find it the docs, but is there an example query that I can send over http that returns records in the last x days? I have something like the following, but stuck on how to replace #inst "2023-04-26T00:00:00.000-07:00" with current time. any tips on simplifying the query are highly appreciated!

{:query {
 :find [(pull ?e [*]) start-time ref-ms diff-ms],
 :where
 [[?e :xt/id]
  [?e :user "user:1"]
  [(get-start-valid-time ?e) start-time]
  [(inst-ms start-time) start-ms]
  [(inst-ms #inst "2023-04-26T00:00:00.000-07:00") ref-ms]
  [(- start-ms ref-ms) diff-ms]
  [(> diff-ms 86400000)]
 ]
 :order-by [[start-time :desc]]
}}

jarohen09:04:13

you could pass it in as an 'in-arg' - would this work for you?

{:query '{:find [(pull ?e [*]) start-time],
          :in [after-ms]
          :where [[?e :xt/id]
                  [?e :user "user:1"]
                  [(get-start-valid-time ?e) start-time]
                  [(inst-ms start-time) start-ms]
                  [(> start-ms after-ms)]]
          :order-by [[start-time :desc]]}
 :in-args [(- (System/currentTimeMillis) 86400000)]}

jarohen09:04:03

this binds the argument to after-ms during the query, then checks the start-ms is after that

jarohen09:04:37

alternatively, if you have one :xt/id in hand (i.e. you're only looking for one entity, and you know its id), you could try the https://docs.xtdb.com/language-reference/datalog-queries/#history-api API?

Xiaomin Wang15:04:03

Hi @U050V1N74 thanks for the reply! is what you pasted clojure? is there a way to pass in-arg in a http request? I couldn’t find an example in the docs

Xiaomin Wang15:04:27

I tried adding [(System/currentTimeMillis) now] in where, and got {"type":"exception","class":".FileNotFoundException"}