@jrwdunham Neither of these indices is sorted by transaction time, if this is what you need. @konrad.kuehne Can we use one of the history indices for that?
@whilo so are you saying that I canNOT assume that the following will always be true:
(= (->> (d/datoms @conn :aevt :db/txInstant)
reverse
(map first))
(->> (d/datoms @conn :aevt :db/txInstant)
(sort-by (fn [[_ _ tx-time _]] tx-time))
reverse
(map first))) ;; => true
The history index does not care about the time. It only stores entites, that are retracted from the core index either by :db/retract
or updating an entity. The order that can satisfy your idea is the transaction id that is monotonically increasing. So with :aevt
you should get the datoms in order.
Thanks @konrad.kuehne.
🌊
🎵
Question.... is there a db.type for time?
Ah there is! instant 🙂 thnx
So I do a query on my database,
(println (d/q '[:find ?m
:where
[?m :message/kind "chatroom"]
[?m :message/title "Beginners"]]
@conn))
works great, returns a set
#{[Grammar] [Beginners] [Vocabulary] [にほんご] [Translation]}
But when I try to do an on-the-fly argument from a destructured compojure route, using (str room-name) instead of "Beginners" or something like that... I get no results.
(defn room-handler [room-key ring-req]
...
...
(if-let [rk-set
(d/q '[:find ?m
:where
[?m :message/kind "chatroom"]
[?m :message/title (str room-key)]]
@conn)]
(println "rk-set : " rk-set)
)
The invocation (str room-key) ... really room-name... does not give me any results ;x
So yeah, rather than hardcoding a string... how can I put a string variable in the query ?
hi @sova, would be something like this
(d/q '[:find ?m
:in $ ?room-name
:where
[?m :message/kind ?room-name]
[?m :message/title (str room-key)]]
@conn
"chatroom")
oh wow
I might be wrong, but datahike follows the syntax of datascript, therefore there are tons of tutorials here https://github.com/kristianmandrup/datascript-tutorial
that might be useful
Right on.. Yeah no luck with that line quite yet
I thought something like that would work, but I still get an empty result set
thanks for the :in $ line... forgot about that from datomic land
but I am not sure what I'm missing now
looking at that piece that I pasted here, the room-key is kind of alien to that query, right?
because it is not binded to anyhting
When I print the result to console I get
#{[Grammar] [Beginners] [Vocabulary] [にほんご] [Translation]}
notably not in quotes... not a prob?maybe (str ?room-key) works
room-key is bound earlier by something else
but I don't have the literal ... just a variable that should be equivalent
the literal works great, but the variable apparently not so... maybe i am missing something with what happens to this string
your first println
I would covert as follows
(println (d/q '[:find ?m
:in $ ?kind ?title
:where
[?m :message/kind ?kind]
[?m :message/title ?title]]
@conn
"chatroom"
"Beginners"))
should yield the same results
and how you can change "chatroom" a d "Beginners" by the vars you destructured
Oh. that's awesome let me try that
@iagwanderson you're a genius!
two fives way in the air for ya, 5️⃣5️⃣
hehe great.
depending on how you get these inputs.. there are other forms of binding of inputs
(println (d/q '[:find ?m
:in $ [?kind ?title]
:where
[?m :message/kind ?kind]
[?m :message/title ?title]]
@conn
["chatroom" "Beginners"]))
for example, must be valid
good read here: https://docs.datomic.com/on-prem/query.html#inputs
(idk if all works with datahike, but I would assume they do.)
thanks very much
That helps a lot.