An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

clojure.java.jdbc 0.3.0 Released!

December 17, 2013 · No Comments

The "gold" release of the Clojure contrib library that wraps JDBC is now available on Maven Central. This release has been in the works for most of this year, as it introduces large changes from the previous "gold" release (0.2.3) that aim to make the library more idiomatic and easier to use in a multi-threaded functional environment. In order to provide a smooth migration path, the old API from the 0.2.3 release has been moved wholesale to the clojure.java.jdbc.deprecated namespace, and the new API in 0.3.0 uses new naming for almost all of the (new) functionality.

The main API change is the removal of the dynamic global variable *db* and the with-connection macro. Instead you now pass the database spec as an explicit argument in all calls, and you can share connections across multiple SQL operations either by using connection pooling (recommended) or the new with-db-connection macro that takes an explicit binding for (a connected version of) the database spec.

A common problem with the old API when performing queries was that with-query-results required care because the result set was lazily constructed and it was easy to let that lazy sequence escape and have the connection closed before you had finished working on the results. The new API provides a query function that, by default, fully realizes the result set to avoid that problem. You can still process very large result sets lazily by passing :row-fn and/or :result-set-fn arguments to query.

For more details of the new API, you can read the reference documentation for clojure.java.jdbc. For a summary of all the changes made since the 0.2.3 release, read the clojure.java.jdbc change log on Github. To use the library in your project, see the clojure.java.jdbc dependency information on Github.

Detailed documentation on using clojure.java.jdbc is being developed for the Clojure Documentation Site and will be found in the java.jdbc section of the Clojure ecosystems area, once the site has been refreshed from the markdown sources on Github.

Tags: clojure

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment

Leave this field empty