Skip to content

Instantly share code, notes, and snippets.

@yurrriq
Created April 6, 2015 19:11
Show Gist options
  • Select an option

  • Save yurrriq/c1aa39f15b4766899c2b to your computer and use it in GitHub Desktop.

Select an option

Save yurrriq/c1aa39f15b4766899c2b to your computer and use it in GitHub Desktop.
Insert many entities into Datomic at once
(require '[datomic.api :as d])
(let [uri "datomic:dev://localhost:4334/example"
coll (map (fn [k v] {k v})
(map (comp keyword str char) (range 97 123))
(iterate inc 0))
conn (d/connect uri)]
(->> (map (fn [m] (assoc m :db/id (d/tempid :db.part/user))) coll)
(d/transact conn)))
;; {:db/id #db/id [:db.part/user] ...}
;; will fail because the tempid will be the same accross the collection.
;; Mapping (d/tempid :db/part/user) across the data will assign
;; a unique tempid to each map in the collection.
(->> (map (fn [k v] {k v})
(map (comp keyword str char) (range 97 123))
(iterate inc 0))
(map (fn [m] (assoc m :db/id (d/tempid :db.part/user))))
(map :db/id)
(distinct?)
(assert))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment