Created
March 8, 2012 18:39
-
-
Save stuarthalloway/2002582 to your computer and use it in GitHub Desktop.
Datomic extent query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Datomic example code | |
;; | |
;; The extent of entity ?x is all datoms that are about ?x. | |
;; Drop this into your rules. | |
;; | |
;; Demonstrates | |
;; | |
;; 1. recursive query (extent calls itself) | |
;; 2. disjunction (different extent bodies are ORed) | |
;; 3. component attributes (e.g. your arm is a component, your brother isn't) | |
;; 4. navigating inbound and outbound references | |
'[[(extent ?x ?e ?a ?v) ;; match datoms where x is entity... | |
[?e ?a ?v] | |
[?x ?a ?v] | |
[(= ?e ?x)]] | |
[(extent ?x ?e ?a ?v) ;; ...or match datoms where x is value | |
[?e ?a ?v] | |
[?e ?a ?x] | |
[(= ?v ?x)]] | |
[(extent ?x ?e ?a ?v) ;; recurse where y is a component of x | |
(components ?x ?y) | |
(extent ?y ?e ?a ?v)] | |
[(components ?p ?c) ;; only follow component attributes | |
[?a :db/isComponent] | |
[?p ?a ?c]]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment