Last active
May 7, 2020 09:37
-
-
Save edas/f122581a92c278119b21bfd64f813aab to your computer and use it in GitHub Desktop.
Revisions
-
edas revised this gist
May 7, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,9 +10,9 @@ def with_tx(conn) conn.exec("SAVEPOINT #{name}") yield conn conn.exec("RELEASE SAVEPOINT #{name}") rescue conn.exec("ROLLBACK TO SAVEPOINT #{name}") raise end when PQTRANS_INERROR raise "Error" -
edas created this gist
May 7, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ def with_tx(conn) case conn.transaction_status when PQTRANS_IDLE, PQTRANS_ACTIVE conn.transaction do |conn| yield conn end when PQTRANS_INTRANS name = "savepoint_" + SecureRandom::alphanumeric begin conn.exec("SAVEPOINT #{name}") yield conn conn.exec("RELEASE SAVEPOINT #{name}") rescue e conn.exec("ROLLBACK TO SAVEPOINT #{name}") throw e end when PQTRANS_INERROR raise "Error" when PQTRANS_UNKNOWN raise "Unknown" end end