Great will do. Honestly this is one the best documentations I've ever read! It's very clear and goes straight to the point 👌, I'll keep it in mind when writing my own docs.
Thank you. I do not consider myself to be a good writer of documentation -- at one of my previous jobs, after I left, they hired a technical writer specifically to rewrite all the in-house docs I'd written! 😂
an alternative way to look at it, a developer was able to maintain a trove of documentation that otherwise required a dedicated technical writer
I want to test a function that uses next.jdbc/with-transaction
, so far I have been wrapping functions in tests with (next.jdbc/with-transaction [tx ds {:rollback-only true}])
, but seems like the nested transaction commits changes to the db, even though the outer is rollback only. How do I work around this?
@posobin See https://cljdoc.org/d/seancorfield/next.jdbc/1.1.613/api/next.jdbc.transaction#*nested-tx*
(I haven't added that to the Transactions page of the docs yet because I'm not sure I want to encourage people to use it much)
In your case, (binding [next.jdbc.transaction/*nested-tx* :ignore] ... your test ...)
should do what you need.
i.e., with the :rollback-only true
tx inside that binding.
Thank you! But I guess that means that such code is not encouraged?
Well... cloure.java.jdbc
's default behavior was :ignore
which is different. I haven't really had a chance to extensively test behavior around nested TX. So it's fine for you to use it in tests at this point I think.
But be aware that if you bind it to :ignore
for tests, you won't detect any cases where you nest TX accidentally in your non-test code.
I just haven't really decided how best to write this up...
I plan to add it to the c.j.j migration docs for sure, since it's a way to match c.j.j's behavior, but in general you can't nest TX -- and the behavior if you attempt it varies from DB to DB.