I'm sorry if this is painfully obvious, but how do I represent logical disjunction in Datomic? For instance, if I'm looking for an entity whose name is "1" or whose age is less than 5, how would I go about that?
Thanks!
As of 0.9.5130, you can write disjunctive queries directly:
(q '[:find ?e
:where
(or-join [?e]
[?e :name "1"]
(and [?e :age ?age]
[(< ?age 5)]))]
db)
For a quick overview of the new functionality, check out the blog post where they announced it.
You can accomplish this by using rules. An example from the docs shows a rule form that expresses logical OR:
In this case, the rule defines two logical paths to meet the definition "social-media." So, either community/type twitter or community/type facebook-page meet the criteria for "social media." This example is fleshed out in more detail towards the end of the "querying with rules" section of the tutorial.
This example combines multiple logical pathways to inclusion in
southern
-:region/sw
,region:se
, andregion:s
, as well as multiple pathways intosocial media
.