【问题标题】:What is the difference between the user-specified transaction temp-id and the one returned from a transaction, in Datomic?在 Datomic 中,用户指定的事务临时 ID 和从事务返回的临时 ID 有什么区别?
【发布时间】:2016-04-01 09:28:20
【问题描述】:

我有以下与 Datomic 数据库交互的 clojure 函数:

(defn demo-tran [term description]
(d/transact conn
          [{:db/id (d/tempid :db.part/utility -10034)
            :utility.tag/uuid (d/squuid)
            :utility.tag/term term
            :utility.tag/description description}]))

然后我在 repl 中运行它:

(demo-tran "Moo" "A bovine beast")

这成功了,我得到了一个“交易地图”:

{:db-before datomic.db.Db,
 @f4c9aa60 :db-after,
 datomic.db.Db @908ec69f,
 :tx-data [#datom[13194139534424 50 #inst"2016-04-01T09:16:50.945-00:00" 13194139534424 true]
       #datom[668503069688921 153 #uuid"56fe3c82-8dbd-4a0d-9f62-27b570cbb14c" 13194139534424 true]
       #datom[668503069688921 154 "Moo" 13194139534424 true]
       #datom[668503069688921 155 "A bovine beast" 13194139534424 true]],
 :tempids {-9222699135738586930 668503069688921}}

我已将此事务的 tempid 指定为“-10034”,因此我希望在 :tempids 映射中找到该负数。相反,我找到了 -9222699135738586930。这令人困惑。这是怎么回事?

我希望能够让 demo-tran 函数返回新的 EntityID,但是(除了猜测 :tempids 映射中的位置)鉴于我的输入,没有办法得到这个值。

【问题讨论】:

标签: clojure datomic


【解决方案1】:

正如一位评论者提到的(通过链接),您需要使用 resolve-tempid,如文档中的 here 和在 datomic 项目 here 当天演示的那样。

在你的情况下,这将是这样的:

(let [my-tempid (d/tempid :db.part/utility -100034)
      tx-result @(d/transact conn [{:db/id my-tempid
                                    :your "transaction"}])
      db-after (:db-after tx-result)
      tempids (:tempids tx-result)]
  (d/resolve-tempid db-after tempids my-tempid))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 1970-01-01
    • 2017-06-27
    • 2010-09-29
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多