Transaction Functions

Datomic Cloud provides the following built-in transaction functions:


The :db/retractEntity function takes an entity id as an argument. It retracts all the attribute values where the given id is either the entity or value, effectively retracting the entity's own data and any references to the entity as well. Entities that are components of the given entity are also recursively retracted.

The following example transaction data retracts two entities, specifying one of the entities by id, and the other by a lookup ref.

[[:db/retractEntity id-of-jane]
 [:db/retractEntity [:person/email ""]]]


The :db/cas (compare-and-swap) function takes four arguments: an entity id, an attribute, an old value, and a new value. If the entity has the old value for attribute, then the new value will be asserted. Otherwise, the transaction will abort and throw an exception.

You can use nil for the old value to specify that the new value should be asserted only if no value currently exists.

The following example transaction data sets entity 42's :account/balance to 110, if and only if :account/balance is 100 at the time the transaction executes:

[[:db/cas 42 :account/balance 100 110]]