Skip to content

Instantly share code, notes, and snippets.

@logaan
Created July 15, 2012 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logaan/3115870 to your computer and use it in GitHub Desktop.
Save logaan/3115870 to your computer and use it in GitHub Desktop.
;; 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