Why does Datomic yield the same temporary ID twice in a row when iterating?

你离开我真会死。 提交于 2019-11-29 16:04:05

Use

(require '[datomic.api :as d])
(repeatedly 2 #(d/tempid :db.part/user))
;; => (#db/id[:db.part/user -1000118] #db/id[:db.part/user -1000119])

Consider that #... are reader macros meaning that their value will be resolved when the expression is read which naturally happens only once. Use the #... macro only when you are writing literal transaction data (like a schema). Use datomic.api/tempid to generate tempids in runtime.

Because repeat is repeating the value it got from calling id once.

Use repeatedly instead.

See examples at http://clojuredocs.org/clojure_core/clojure.core/repeatedly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!