Closed boechat107 closed 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.
defdb
_default
transaction
*current-db*
`(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?
Sorry, the solution was simple:
(binding [*current-conn* (get-connection my-db))] (transaction ... ))
If you're not setting default db, you can wrap you're code with (with-db my-db ..)
(with-db my-db ..)
I have created my db connection dynamically, without using
defdb
or setting the_default
connection. Then I tried to use thetransaction
macro, but it couldn't find a connection, because there is no*current-db*
or_default
connection.https://github.com/korma/Korma/blob/master/src/korma/db.clj#L228
Should I always set the default db to make a transaction?