Last active
January 23, 2016 16:50
-
-
Save tylermorten/d8484a07229ec4d4f5ff to your computer and use it in GitHub Desktop.
datomic compose identifier
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
{: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])}} |
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
(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