An Architect's View

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

An Architect's View

April 23, 2011 ·

As folks have no doubt realized, I'm using Clojure more and more these days and just embarked on a project at work to replace the CFML-based ORM "Reactor" in our codebase with a much more lightweight ORM written in Clojure (enclosed in a lightweight CFML wrapper). While I've been sketching out the code for that, I've been using the clojure.contrib.sql library, one of a fairly large selection of somewhat ad hoc utilities contributed over the last several years by various Clojure community members. As part of the 1.3.0 release of Clojure, currently in development, the Clojure/core team have decided an overhaul of the contrib libraries is needed and so they requested dedicated library maintainers to step forward to work on newer versions of popular libraries as they are promoted to new namespaces within the Clojure ecosystem.

Once clojure.contrib.sql's new namespace was approved a the new github repository created, I started work on migrating Steve Gilardi's code, removing dependencies on old clojure.contrib libraries and getting a maven build working. Since then, I've put out a general call for feedback on the Clojure mailing list and started to make some changes to the library itself:

  • Insert operations now return generated keys
  • A new, single record insertion function is available: insert-record

Generated keys are returned as a structmap from insert-record and as a sequence of structmaps from insert-records. Generated keys are also returned as a structmap from calls to insert-values that only perform one insert (insert-values can be used to insert multiple rows in a single SQL statement). 0.0.1-SNAPSHOT builds are already available from the Sonatype OSS snapshots repository. If you're using Leiningen, just add the following to your project.clj file:

  :repositories { "sonatype" "" }
  :dependencies [[org.clojure/java.jdbc "0.0.1-SNAPSHOT"] ...]

I've already received some good feedback and I'm starting to accumulate issues on the github site as I figure out what needs doing and how best to do it to take the library to the next level. If you have feedback, feel free to post it to that Google Groups thread, here in comments or directly to me (using the Contact Me! link on the right).

As for the lightweight ORM, that's working pretty nicely. On top of the library it required just fifty line of (well-commented) Clojure code, a generic persistent CFC base class (about 100 lines) and a simple ORM service (25 lines) to create beans and inject the Clojure ORM code. Beans can load, save and delete themselves (using the injected Clojure code). If work allows me to open source it, I'll add it to my cfmljure project as part of the examples.

Tags: clojure · coldfusion · oss

2 responses

  • 1 Ian Phillips // Apr 24, 2011 at 5:33 AM

    I'm curious, how do you see this stacking up against ClojureQL? When would you use one vs. the other?
  • 2 Sean Corfield // Apr 24, 2011 at 8:28 PM

    @Ian, I guess it depends on whether you want to use raw SQL or a DSL - and also whether you want to depend on just the "core" (language + official libraries) or a third party library?