Search code examples
consistencydatomic

Datomic: on a Peer, does Connection.db() read your writes after Connection.transact()


Consider the following operations, occuring in a Datomic Peer:

(require '[datomic.api :as d])

(let [;; running a transaction and awaiting completion
      tx-res @(d/transact-async conn tx-data)
      ;; reading the current database value
      db1 (d/db conn)]
  ,,,)

In the consistency model of Datomic, can I expect the changes made by tx-res to be visible in db1?

(I know about both :db-after (d/sync conn t), but it can be practical to rely on reading your writes on the Connection, e.g for doing successive writes on a connection without having to carry along database values).


Solution

  • Val,

    Yes, db1 would include the changes made in the transaction. However, this approach is considered bad practice, as you're reading the same value twice (tx-res already has the value of the resulting db). Further, you're not guaranteed that db1 is the same database value as the :db-after from the transaction.

    We highly recommend using the :db-after as returned from the transaction for a subsequent read.

    -Marshall