Skip to content

Instantly share code, notes, and snippets.

@tylermorten
Last active January 23, 2016 16:50
Show Gist options
  • Save tylermorten/d8484a07229ec4d4f5ff to your computer and use it in GitHub Desktop.
Save tylermorten/d8484a07229ec4d4f5ff to your computer and use it in GitHub Desktop.
datomic compose identifier
{:db/id #db/id[:db.part/db]
:db/ident :createWithComposedID
:db/fn #db/fn {:lang "clojure"
:params [db m compose-assoc existing-assoc parent-ident]
:code (let [parent (d/entity db parent-ident)
newRecord (merge m {:db/id (d/tempid :db.part/user)
compose-assoc (str (:db/id parent) ":" (existing-assoc m))})]
[new-record])}}
(require '[datomic.api :as d])
(def conn (d/connection "datomic:mem://testdb"))
(def parent-id (ffirst (d/q '[:find ?e
:where [?e :parent/gid #uuid"blah"] (d/db conn))))
(d/transact conn [[:createWithComposedID {:product/number "1001A"
:product/price 13.50
:parent/_products parent-id} :product/id :product/number parent-id]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment