Datomic Client API equivalent to on-prem tx->t


#1

I’m experimenting with datomic cloud. In datomic on-prem, if I’m not mistaken, we can fetch the basis t value of a database at the moment a given transaction completed with the d/tx->t function. I couldn’t find an equivalent in the peer client api documentation. Is it possible to achieve the same result through other means?


#2

Hi Rafael,

We discussed this issue in a support case and you correctly asked that we cross post our discussion here (sorry for missing the initial post) to help any future dev in the same situation. I am going to summarize and post our my response below:

Your reply indicated that you specifically needed d/tx ->t for idempotency violation detection (we do not currently have d/tx->t in client). You wanted to be able to send outgoing messages based on database state as it was when you first transacted the data. In the peer library you were able to use the helper function d/tx->t with a transaction id to pass the database as-of that point in time for the computation of further effects.

I proposed the following alternative for your specific use case on client, with the caveat that we are still evaluating helper functions for datomic client cloud:

Hi Rafael,

Thank you for the added context. While we do not have the helper function tx -> t, I do believe we can provide an alternative pattern. The client API supports as-of, which will allow you to pass a time-point. A time-point can be a database t, a tx, or a date. Because transactions are always in ascending order (just like ts), you could pass as-of the transaction directly.

For an example I pulled the following from our day-of-datomic cloud (which uses the client library):

(d/q
  '[:find (max 3 ?tx)
    :where
    [?tx :db/txInstant]]
  db)
=> [[[13194139533327 13194139533326 13194139533325]]]


(def db-before (d/as-of db 13194139533327))

(d/q
  '[:find ?sku ?count
    :where
    [?inv :inv/sku ?sku]
    [?inv :inv/count ?count]]
  db-before)

(d/q
  '[:find ?sku ?count
    :where
    [?inv :inv/sku ?sku]
    [?inv :inv/count ?count]]
  db-before)
=> [["SKU-42" 1000] ["SKU-21" 7]]

I’ve communicated the need for helper functions like tx -> t to the development team, but hopefully the alternative I’ve provided will work for your use case.