This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-28
Channels
- # aleph (7)
- # babashka (13)
- # beginners (10)
- # biff (4)
- # calva (75)
- # cljs-dev (22)
- # clojure (55)
- # clojure-berlin (1)
- # clojure-europe (15)
- # clojure-nl (1)
- # clojure-norway (35)
- # clojure-serbia (1)
- # clojure-uk (2)
- # clojurescript (46)
- # community-development (1)
- # core-async (23)
- # data-science (1)
- # datalevin (2)
- # datascript (10)
- # datomic (11)
- # fulcro (28)
- # helix (12)
- # hyperfiddle (26)
- # introduce-yourself (4)
- # malli (16)
- # off-topic (1)
- # pathom (4)
- # pedestal (1)
- # polylith (12)
- # quil (11)
- # releases (3)
- # scittle (24)
- # shadow-cljs (85)
- # specter (1)
- # sql (9)
- # xtdb (5)
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?But because of overhead on parsing/executing and being generic it takes more time doing the query
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)))