I have a question, I read the datascript 2 blog post and I keep wondering about this
> Well, it surprised me as well that in 3 years of full-time web app development with DataScript I haven’t used a single query.
The place where I use queries is when I want to grab an eid that is on the other side of a :db.unique/identity attribute like this. I have a linked list of messages, and a main chat object that points to the last message in that history. I have the chat entity and I want to get the last message entity so I do this.
(defn last-chat-message [db chat-eid]
(d/q '[:find ?message .
:in $ ?chat
:where
[?chat :chat/last-message ?message]]
db chat-eid))
How would I do this with the entity api?Looks like I added find-datom that replaces d/datoms + first
Still feels clumsy though
Ahhh, good idea. Something like this?
(defn find-datom [db idx & args]
(first (apply d/datoms db idx args)))
(defn find-ent [db idx & args]
(:e (apply find-datom db idx args)))
(defn find-attr [db idx & args]
(:a (apply find-datom db idx args)))
(defn find-value [db idx & args]
(:v (apply find-datom db idx args)))
(defn find-tx [db idx & args]
(:tx (apply find-datom db idx args)))Yeah, and find-datom is already in
(-> (d/datoms db :eavt chat-eid :chat/last-message)
first
:e)Basically query would do the same under the hood
But because of overhead on parsing/executing and being generic it takes more time doing the query
Maybe the fact that I know how it works affects my preference
Thanks! I have done it that way too, but both ways felt kind of wrong to me.