korma / Korma

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

Transaction fails to find a db connection #261

Closed boechat107 closed 9 years ago

boechat107 commented 9 years ago

I have created my db connection dynamically, without using defdb or setting the _default connection. Then I tried to use the transaction macro, but it couldn't find a connection, because there is no *current-db* or _default connection.

`(jdbc/with-db-transaction [conn# (or *current-conn* (get-connection @_default)) :isolation ~isolation :read-only? ~read-only?]

https://github.com/korma/Korma/blob/master/src/korma/db.clj#L228

Should I always set the default db to make a transaction?

boechat107 commented 9 years ago

Sorry, the solution was simple:

(binding [*current-conn* (get-connection my-db))]
   (transaction ... ))
immoh commented 9 years ago

If you're not setting default db, you can wrap you're code with (with-db my-db ..)