Skip to content

Instantly share code, notes, and snippets.

@favila
Last active August 29, 2015 14:05
Show Gist options
  • Save favila/54e8c342deb33e8065f7 to your computer and use it in GitHub Desktop.
Save favila/54e8c342deb33e8065f7 to your computer and use it in GitHub Desktop.
Undo datomic transaction
(defn rollback
"Reassert retracted datoms and retract asserted datoms in a transaction,
effectively \"undoing\" the transaction.
WARNING: *very* naive function!"
[conn tx]
(let [tx-log (-> conn d/log (d/tx-range tx nil) first)
txid (-> tx-log :t d/t->tx)
newdata (->> (:data tx-log)
(remove #(= (:e %) txid))
(map #(do [(if (:added %) :db/retract :db/add) (:e %) (:a %) (:v %)]))
reverse)]
@(d/transact conn newdata)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment