This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-27
Channels
- # bangalore-clj (1)
- # beginners (27)
- # boot (16)
- # cider (14)
- # cljs-dev (94)
- # cljsrn (8)
- # clojure (229)
- # clojure-dev (5)
- # clojure-dusseldorf (6)
- # clojure-italy (8)
- # clojure-norway (8)
- # clojure-russia (22)
- # clojure-sanfrancisco (2)
- # clojure-spec (48)
- # clojure-uk (44)
- # clojurescript (47)
- # core-async (87)
- # cursive (43)
- # datascript (22)
- # datomic (20)
- # defnpodcast (5)
- # emacs (6)
- # hoplon (4)
- # jobs-rus (4)
- # keechma (2)
- # klipse (8)
- # leiningen (2)
- # luminus (2)
- # lumo (14)
- # om (38)
- # onyx (4)
- # overtone (3)
- # pedestal (41)
- # planck (72)
- # powderkeg (42)
- # proton (46)
- # protorepl (9)
- # reagent (9)
- # ring (47)
- # ring-swagger (5)
- # rum (7)
- # sql (22)
- # unrepl (1)
- # untangled (24)
- # vim (19)
- # yada (5)
how can I query for one or the other:
(d/q '[:find ?thing
:where
(or [?thing :attribute]
[?thing :maybe-existing-attribute])
]
(-> (d/create-conn {})
(d/transact! [{:db/id -1 :attribute true}])
:db-after
))
the error here is cannot compare :attribute to [?thing :attribute]
but looking at this example I'd kind of expect it to work:
https://github.com/tonsky/datascript/blob/3fbe1d842f14e176a0fb26a28a41a721eda6a417/test/datascript/test/query_or.cljc#L28
(let [conn (ds/create-conn)
rules '[[(has-foo-or-bar ?e)
[?e :foo]]
[(has-foo-or-bar ?e)
[?e :bar]]]]
(ds/transact! conn [{:foo 1} {:bar 2} {:baz 3} {:foo 4 :bar 4}])
(ds/q '[:find [?e ...]
:in $ % ;<--- '%' is for passing rules into query
:where
(has-foo-or-bar ?e)]
@conn rules))
=> [4 2 1]
(->> ids (ds/pull-many @conn '[*])))
=> [{:db/id 4, :bar 4, :foo 4} {:db/id 2, :bar 2} {:db/id 1, :foo 1}]
basically, to have an or
, you write a bunch of rules (one per or
branch) with identical signature (name, args), and pass them into query together
it is either "by convention" or "by implementation", I don't actually know which one is it (in datascript)
docs are pretty much datomic ones: http://docs.datomic.com/query.html
I didn't try the test I assumed they work, but my example was so similar I couldn't see how they're different.
https://clojurians-log.clojureverse.org/datascript/2017-03-07.html https://clojurians-log.clojureverse.org/datascript/2017-03-08.html
not sure what those or
are about, might be just boolean or, however it looks like query or to me too