Skip to content

Instantly share code, notes, and snippets.

@a2ndrade
Created June 20, 2013 04:44
Show Gist options
  • Save a2ndrade/5820364 to your computer and use it in GitHub Desktop.
Save a2ndrade/5820364 to your computer and use it in GitHub Desktop.
Datomic: nested component entities
;; see http://stackoverflow.com/questions/16242750/nesting-structures-with-datomic
(require '[datomic.api :as d])
(def uri "datomic:mem://test")
(d/create-database uri)
(def conn (d/connect uri))
;; sample attributes
(d/transact conn [{:db/id #db/id[:db.part/db]
:db/ident :some/ref-value
:db/valueType :db.type/ref
:db/isComponent true
:db/cardinality :db.cardinality/many
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :some/list-value
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db.install/_attribute :db.part/db}])
;; see http://blog.datomic.com/2013/06/component-entities.html
;; [["a" "b" "c"]["d" "e" "f"]]
(d/transact conn [{:db/id #db/id[:db.part/db]
:some/ref-value [{ :some/list-value ["a" "b" "c"]}
{ :some/list-value ["d" "e" "f"]}]}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment