0

I have the following clojure function which transacts to a Datomic database:

(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}]))

I then run this in the repl:

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

This succeeds and I am given back a 'transaction map':

{: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}}

I have specified the tempid for this transaction as '-10034' so I would expect to find that negative number in the :tempids map. Instead I find -9222699135738586930. This is confusing. What is going on here?

I was hoping to be able to have the demo-tran function return the new EntityID but (other than guessing the position in the :tempids map) there is no way, given my inputs, to get to this value.

Zuriar
  • 11,096
  • 20
  • 57
  • 92

1 Answers1

1

As one commenter mentions (via link), you need to use resolve-tempid, as documented here and demonstrated in the day of datomic project here.

In your case this would be something like:

(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))
Ben Kamphaus
  • 1,655
  • 10
  • 13