Fork me on GitHub

has anyone got a datomic -> prometheus metric exporter?


I had a datomic -> statsd thing a couple years ago, extending to prometheus would be nice. (I ❤️ prometheus)


Why is it that if I am transacting data to update an existing entity and I use a lookup ref to uniquely identify the entity, the the transaction report contains a :tempids map containing a tempid that maps to the :db/id that I updated? If I perform the same transaction to the same existing entity but this time use a :db/id to uniquely identity it, the transaction report's :tempids map is empty. Why is there this inconsistency?


Here's an example that uses the lookup ref :entity/id which is marked as :db/unique :db.unique/identity.

@(d/transact conn [{:entity/id #uuid"591b634f-0c58-4739-9d15-ddc524eaabd2"
                    :user/name "Cynthia"}])
{:db-before datomic.db.Db,
 @ffa0ca67 :db-after,
 datomic.db.Db @b4fe535a,
 :tx-data [#datom[13194139534336 50 #inst"2017-05-22T21:43:01.218-00:00" 13194139534336 true]],
 :tempids {-9223301668109598102 312261302289389}}
And an example performing the same transaction using :db/id instead:
@(d/transact conn [{:db/id     312261302289389
                    :user/name "Cynthia"}])
{:db-before datomic.db.Db,
 @b4fe535a :db-after,
 datomic.db.Db @bafb05cb,
 :tx-data [#datom[13194139534337 50 #inst"2017-05-22T21:43:12.516-00:00" 13194139534337 true]],
 :tempids {}}


However, if I transact using the normal lookup ref syntax it I get the expected behavior:

@(d/transact conn [{:db/id [:entity/id #uuid"591b634f-0c58-4739-9d15-ddc524eaabd2"]
                    :user/name "Cynthia"}])
{:db-before datomic.db.Db,
 @1f813257 :db-after,
 datomic.db.Db @b1cfceb4,
 :tx-data [#datom[13194139534344 50 #inst"2017-05-22T22:04:15.797-00:00" 13194139534344 true]],
 :tempids {}}


Ah, I think I found my answer: TIL: > If a transaction specifies a unique identity for a temporary id, and that unique identity already exists in the database, then that temporary id will resolve to the existing entity in the system. This upsert behavior makes it possible for transactions to work with domain identities, without ever having to specify Datomic entity ids.