Created
April 6, 2015 19:11
-
-
Save yurrriq/c1aa39f15b4766899c2b to your computer and use it in GitHub Desktop.
Insert many entities into Datomic at once
This file contains hidden or 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]) | |
| (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