This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-02
Channels
- # announcements (13)
- # babashka (42)
- # beginners (29)
- # calva (39)
- # cider (15)
- # clerk (10)
- # clojure (67)
- # clojure-europe (18)
- # clojure-hungary (2)
- # clojure-nl (1)
- # clojure-norway (12)
- # clojure-uk (7)
- # clojuredesign-podcast (14)
- # clojurescript (19)
- # datalevin (1)
- # datascript (5)
- # emacs (4)
- # events (2)
- # fulcro (5)
- # graalvm (5)
- # hyperfiddle (23)
- # incanter (3)
- # jobs (2)
- # lsp (8)
- # missionary (15)
- # off-topic (45)
- # portal (41)
- # practicalli (1)
- # re-frame (3)
- # reitit (6)
- # releases (2)
- # remote-jobs (1)
- # sci (1)
- # shadow-cljs (35)
- # solo-full-stack (8)
- # tools-deps (4)
Can someone share some examples of using get-else
and or-join
to perform some logic in a DataScript/Datomic query? Trying to do something like:
(def db (atom (d/empty-db {:worksheet/inputs {:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}})))
(d/transact db [{:worksheet/name "Worksheet"
:worksheet/inputs [{:input/kind :discrete
:input/value 0}
{:input/kind :continuous
:input/value 10
:input/units "feet"}]}])
;; Only get the units when the input is :continuous
(d/q '[:find ?w-name ?i ?value ?units
:where
[?w :worksheet/name ?w-name]
[?w :worksheet/inputs ?i]
[?i :input/value ?value]
(or-join [?units]
(and
[?i :input/kind :continuous]
[?i :input/units ?units])
[(ground :none) ?units])]
@db)
And instead of getting:
#{["Worksheet" 3 10 "feet"] ["Worksheet" 2 0 :none]}
I’m getting:
#{["Worksheet" 3 10 "feet"] ["Worksheet" 3 10 :none] ["Worksheet" 2 0 :none] ["Worksheet" 2 0 "feet"]}