Reputation: 145
I am working with or
clause in datomic.
I know that using or
in this query I get the users with :user/first-name "Mia"
and users with :user/first-name "Wallace"
.
(d/q
'[:find ?u
:where
(or [?u :user/first-name "Mia"]
[?u :user/last-name "Wallace"])]
(d/db conn))
But I would like a clause that works like Clojure's or
. That's it, I want users with :user/first-name "Mia" and if there is not, I want to find the ones with :user/last-name "Lucas"
. Is it possible to do that in one query? I know that I can do it with two queries.
Upvotes: 1
Views: 339
Reputation: 29958
You can do that using either a Collection Binding or a Relation Binding. From the docs:
A collection binding binds a single variable to multiple values passed in as a collection. This can be used to ask "or" questions, i.e. what releases are associated with either Paul McCartney or George Harrison?
;; query
[:find ?release-name
:in $ [?artist-name ...]
:where [?artist :artist/name ?artist-name]
[?release :release/artists ?artist]
[?release :release/name ?release-name]]
;; inputs
db, ["Paul McCartney" "George Harrison"]
;; result
#{["My Sweet Lord"]
["Electronic Sound"]
["Give Me Love (Give Me Peace on Earth)"]
["All Things Must Pass"]
...}
Upvotes: 2