If datalevin's databases are mutable references not static values, what's the purpose of :db-before and :db-after in transaction reports? Shouldn't they be equivalent?
they allow people to compare the db state changes. Very useful to verify upsert, replacement, component retraction, etc. And critical in tx-data->simulated-report, otherwise, the simulation is useless.
they are not equivalent
So if you query db-before, do you only see datoms that were available prior to the txn?
that's not the difference, The difference is the specific state change that you can verify.
how do you verify it?
same query or pull, different result, e.g.
(let [report (d/transact! conn [{:db/id 101
:account/status :closed}])]
{:before (d/pull (:db-before report) [:account/status] 101)
:after (d/pull (:db-after report) [:account/status] 101)
:datoms (:tx-data report)})
allow you to verify that status changed from :open to :closed,Ok, so querying a db-before can access any datoms that were present in the database prior to the beginning of the txn? Or can it only reliably access the prior state of datoms that were changed in the txn?
yes, it only covers the datoms that touched in the txn
aha, that's an interesting constraint that should be mentioned in the book. You can imagine someone querying another attr on an entity affected in a txn and being surprised that it changed out from under them
will do