introduction

5 views
Skip to first unread message

rb

unread,
Sep 2, 2009, 5:16:08 AM9/2/09
to clj-record-dev
Hi,

I just saw the message form John on the Clojure group about this
group.
I'm not currently using clj-record nor Clojure in production, but I
will be evaluating both to use them in a new product.

I am mainly using postgresql, but I would like this new product to be
independent from a particular database server.
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.

If I understand well, I must be the first non-contributor to post
here, but I hope this will change rapidly!

Looking forward to learning a lot on this forum.

Cheers

Raphaël

John D. Hume

unread,
Sep 3, 2009, 12:44:24 PM9/3/09
to clj-rec...@googlegroups.com
Hi Raphaël,
Thanks for your interest.

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.

--
http://elhumidor.blogspot.com/

Daniel Renfer

unread,
Sep 3, 2009, 7:12:13 PM9/3/09
to clj-rec...@googlegroups.com
I've defined methods for other namespace's multimethods. Just
namespace qualify the name of the method and you're good to go.

John D. Hume

unread,
Sep 4, 2009, 12:02:39 AM9/4/09
to clj-rec...@googlegroups.com
On Thu, Sep 3, 2009 at 7:12 PM, Daniel Renfer<du...@kronkltd.net> wrote:
> namespace qualify the name of the method and you're good to go.

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

--
http://elhumidor.blogspot.com/

Reply all
Reply to author
Forward
0 new messages