Skip to content

Commit

Permalink
Add test for with-transaction
Browse files Browse the repository at this point in the history
Trying to debug
babashka/babashka-sql-pods#47. This also
serves as a good test that basic functionality works.
  • Loading branch information
john-shaffer committed Dec 11, 2021
1 parent bafe650 commit e0d1bd1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/mysql_native_image.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,24 @@
:password "local"
:user "root"})

(defn test-with-transaction!
"Test for https://github.com/babashka/babashka-sql-pods/issues/47
No issues here, but it fails in babashka."
[datasource]
(let [con (jdbc/get-connection datasource)]
(prn (jdbc/execute! con ["drop table if exists foo"]))
(prn (jdbc/execute! con ["create table foo (a int)"]))
(prn (jdbc/execute! con ["insert into foo values (1), (2), (3)"]))
(prn (jdbc/execute! con ["select * from foo"]))
(jdbc/with-transaction [tx datasource]
(Thread/sleep 200)
(prn (jdbc/execute! tx ["select * from foo"]))
(assert (= (jdbc/execute! con ["select * from foo"])
(jdbc/execute! tx ["select * from foo"]))))))

(defn -main [& _]
(let [ds (jdbc/get-datasource db)]
(prn
(jdbc/execute! ds ["select now()"]))))
(jdbc/execute! ds ["select now()"]))
(test-with-transaction! ds)))

0 comments on commit e0d1bd1

Please sign in to comment.