-
-
Save souenzzo/2783a30bc8d5b904a7b1e0ecf8cbe082 to your computer and use it in GitHub Desktop.
This file contains 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
(let [jdbc-url (System/getenv "JDBC_DATABASE_URL") | |
ds (jdbc/get-datasource {:jdbcUrl jdbc-url})] | |
(with-open [test-conn (jdbc/get-connection ds {:auto-commit false})] | |
(jdbc/execute! test-conn | |
["DELETE FROM app_user"]) | |
(jdbc/with-transaction [app-conn test-conn | |
#_{:rollback-only true}] | |
(let [sp (.setSavepoint app-conn)] | |
(try | |
;; here is my app-code; so it should use `jdbc/with-transact` when it needs | |
(jdbc/with-transaction [tx app-conn] | |
(jdbc/execute! tx ["INSERT INTO app_user (username) VALUES (?)" | |
(UUID/randomUUID)])) | |
(finally | |
;; throws: ERROR: ROLLBACK TO SAVEPOINT can only be used in transaction blocks | |
(.rollback app-conn sp))))) | |
;; should be empty again | |
(jdbc/execute! test-conn | |
["SELECT * FROM app_user"]))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment