This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-29
Channels
- # aws (6)
- # beginners (33)
- # bitcoin (2)
- # boot (22)
- # carry (2)
- # cider (5)
- # clara (21)
- # cljs-dev (115)
- # cljsrn (40)
- # clojure (161)
- # clojure-dev (73)
- # clojure-italy (38)
- # clojure-russia (88)
- # clojure-spec (123)
- # clojure-uk (58)
- # clojurescript (88)
- # core-async (26)
- # cursive (5)
- # datascript (18)
- # datomic (26)
- # hoplon (50)
- # java (2)
- # jobs (1)
- # leiningen (10)
- # lumo (1)
- # off-topic (18)
- # om (9)
- # onyx (26)
- # parinfer (13)
- # pedestal (41)
- # quil (1)
- # re-frame (27)
- # reagent (21)
- # ring-swagger (11)
- # slack-help (3)
- # spacemacs (8)
- # specter (5)
- # sql (42)
- # timbre (1)
- # uncomplicate (7)
- # untangled (3)
- # videos (1)
- # yada (26)
Hey guys. I want to query some data that is filtered by a value, but ONLY if that value is not nil. I currently have:
'[:find ?label ?value
:where
[?i :functiontype/functiontype ?label]
[?i :functiontype/functiontypeid ?value]
[?i :functiontype/blocked false]
[_ :offer/function ?fid]
[?j :functions/functionid ?fid]
[?j :functions/functiontypeid ?ftid]
[(or (nil? ?fid) (= ?ftid ?value))]]
but that doesn't seem to work, and also doesn't seem very idiomatic... Could anybody suggest an alternative?(let [rules '[[(exact-or-missing ?e ?a ?v) [?e ?a ?v]]
[(exact-or-missing ?e ?a ?v) (missing? ?e ?a)]]]
(ds/q
'[:find ?label ?value
:in $ % ;; % is a reserved symbol for passing in rules
:where
[?i :functiontype/functiontype ?label]
[?i :functiontype/functiontypeid ?value]
[?i :functiontype/blocked false]
[_ :offer/function ?fid]
[?j :functions/functionid ?fid]
(exact-or-missing ?j :functions/functiontypeid ?value)]
@conn rules))
ah, right. Okay, my question was if it were possible (within one query) to filter if and only if :offer/function wasn't nil
Okay, I got some tips from the folks over at #datomic, and came up with this:
[:find ?label ?value
:where
(or
(and [?i :functiontypes/functiontype ?label]
[?i :functiontypes/functiontypeid ?value]
[(missing $ ?e :offer/function)])
(and [_ offer/function ?fid]
[?i :function/functionid ?fid]
[?i :function/functiontypeid ?value]
[?j :functiontypes/functiontypeid ?value]
[?j :functiontypes/functiontype ?label]))]
This however results in the error Cannot parse clause, expected (data-pattern | pred-expr | fn-expr | rule-expr | not-clause | not-join-clause | or-clause | or-join-clause)
. Can anybody spot my mistake?