clojure.java.jdbc, idiomatic way to use a connection

2013-08-14 Thread Kyle Cordes
Hello. I've coded quite a lot of JDBC usage in Java, and enough Clojure to know my way around pretty well; yet I've been unable to figure out the following by reading the source and docs for clojure.java.jdbc. I've read http://clojure.github.io/java.jdbc/ and many pages linked from there. The

Re: clojure.java.jdbc, idiomatic way to use a connection

2013-08-14 Thread Keith Irwin
I think you can use db-connection, something like: (let [conn (db-connection spec) meta (.getMetaData conn)] (doall (.getTables meta nil schema %s nil)) (.close conn)) Or what have you. I wrote a little macro `with-meta-data` that was something like that, with added

Re: clojure.java.jdbc, idiomatic way to use a connection

2013-08-14 Thread Benny Tsai
Does db-transaction work in your case? Evaluates body in the context of a transaction on the specified database connection. The binding provides the database connection for the transaction and the name to which that is bound for evaluation of the body. See db-transaction* for more details.

Re: clojure.java.jdbc, idiomatic way to use a connection

2013-08-14 Thread Sean Corfield
The `db-spec` can have a `:connection` member and all operations will use that. You are responsible for closing it when you're done. Something like (untested, off the top of my head): (with-open [conn (get-connection db-spec)] (let [db (assoc db-spec :connection conn)] ... (query db