Last active
August 29, 2015 14:05
-
-
Save favila/54e8c342deb33e8065f7 to your computer and use it in GitHub Desktop.
Undo datomic transaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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