korma / Korma

Tasty SQL for Clojure.
http://sqlkorma.com
1.48k stars 222 forks source link

Rewrite with-db to use a dynamic var #234

Closed hlship closed 10 years ago

hlship commented 10 years ago

Really? That's what with-db does?

Ok, that's useful for simple cases and interactive development.

In my situation, I have a complicated application that hits multiple databases, and the database connection details are determined properly, at runtime (based on external configuration and startup code). That means I can't use database with my defentity ... it needs to come later, on each select, insert, etc.

However, something like with-db would be great if it was thread bound. Further, it could get a single connection from the pool and re-use it across all API calls. That would simplify my code and possibly improve performance.

BTW: You should add some labels so I could mark this as a "suggestion".

bitemyapp commented 10 years ago

Created and applied. Added bug too.

hlship commented 10 years ago

I have subsequently discovered clojure.java.jdbc/with-db-connection and am checking that Korma honors that when no explicit DB is specified. So this may end up being more of a docstring issue, to point coders at the right function.

immoh commented 10 years ago

This was actually broken in 0.3.1 while trying to fix other bugs related to with-db, so I consider this more as a bug.

immoh commented 10 years ago

This has been fixed in 0.3.2.