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"]}i think you need ?value in the or-join vector [?value ?units]
https://docs.datomic.com/pro/query/query.html#or-join-clause
can also try plain or
because you want to unify with all vars