Created
July 15, 2012 08:22
-
-
Save logaan/3115870 to your computer and use it in GitHub Desktop.
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
;; Schema | |
{:db/id #db/id[:db.part/db] | |
:db/ident :thing/name | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one | |
:db/fulltext true | |
:db/doc "A thing's name" | |
:db.install/_attribute :db.part/db} | |
{:db/id #db/id[:db.part/db] | |
:db/ident :thing/children | |
:db/valueType :db.type/ref | |
:db/cardinality :db.cardinality/many | |
:db/doc "A thing's child things" | |
:db.install/_attribute :db.part/db} | |
;; Query (does not work) | |
;; Trying to find out what parents Pokahontas has | |
(q '[:find ?name | |
:where [?e :thing/name "Pokahontas"] | |
[?e :thing/_children ?p] | |
[?p :thing/name ?name]] | |
(db conn)) | |
;; This works. But feels super clunky. | |
(def pokahontas | |
(d/entity (db conn) | |
(-> (q '[:find ?e | |
:where [?e :thing/name "Pokahontas"]] | |
(db conn)) | |
first first))) | |
(map #(get % :thing/name) (get pokahontas :thing/_children)) | |
;; For future visitors I figured it out. This works: | |
(q '[:find ?name | |
:where [?e :thing/name "Pokahontas"] | |
[?p :thing/children ?e] | |
[?p :thing/name ?name]] | |
(db conn)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment