On Wed, Sep 2, 2009 at 5:16 AM, rb<raph...@gmail.com> wrote:
> Isn't there a system of adapter, like there is for Ruby on Rails'
> ActiveRecord? That way adding support for a new server is not too hard
> and doesn't touch the core of the system.
At the moment there's no equivalent to ActiveRecord's adapters, though
I'd expect something like that to evolve if certain features are
added.
Right now the only place where clj-record differentiates between DB
vendors is when it retrieves the id of the last inserted record. (This
is in clj-record.util/id-query-for.) There's also a multimethod in the
test setup script that figures out how to define an auto-incrementing
id column, but that's not really part of the library. In both cases
the subprotocol of the db-spec is the value the code switches on.
I've never done a defmethod on another namespace's multimethod, but I
believe that's supported in Clojure. If so that would probably be my
prefered approach for "adapters." Note however that I haven't spent
much time thinking about this.
-hume.
Great. I just pushed a change[1] that implements id-query-for as a
multimethod, so if you're looking to make clj-record work with another
dbms, you can do something like this (if you've got clj-record.util
:as util).
(defmethod util/id-query-for "fake subprotocol" [db-spec table-name]
(str "made up query"))
-hume.
[1] http://github.com/duelinmarkers/clj-record/commit/99cf06753a080f69f3c5bc1b57089e67603c953b