clj-record using ClojureQL?

10 views
Skip to first unread message

John D. Hume

unread,
Jan 18, 2010, 10:08:13 AM1/18/10
to clj-rec...@googlegroups.com
Hi folks,
For the last few months (after working on a Django app for the first
time) I've been thinking about adding a first class query concept to
clj-record. I imagined it might look like this:

(def query (person/make-query))
(def adult-q (q/add-predicate query :age q/greater-than 17))
(def draftable-q (q/add-predicate adult-q :sex q/equals "M"))
(manufacturer/find-all draftable-q))
; SELECT * FROM manufacturers WHERE age > 17 AND sex = 'M'

In practice these would most likely be useful in the same way named
scopes are useful in ActiveRecord, and they could be composable in a
similar way.

(def males (q/add-predicate (person/make-query) :sex q/equals "M"))
(def adults (q/add-predicate (person/make-query) :age q/greater-than 17))
(def draftables (q/compose males adults))

So first, does this seem useful?

Next, this isn't an original idea. In fact it's pretty close to some
things already supported in ClojureQL. What are your thoughts on
clj-record using ClojureQL as its SQL generator and exposing its query
API? Looking at the code briefly, I don't think ClojureQL actually
supports adding predicates to queries right now, but this seems like
an easy addition. This would have the advantage of giving us easy
vendor-neutral access to everything those guys have already
implemented and new clj-record query features for free (or at least
cheap) as ClojureQL moves forward. (It also means I can throw away my
least favorite parts of clj-record.)

Thoughts?
-hume.

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

Ed Bowler

unread,
Jan 18, 2010, 10:17:02 AM1/18/10
to clj-rec...@googlegroups.com
On Mon, Jan 18, 2010 at 3:08 PM, John D. Hume <duelin....@gmail.com> wrote:
> Hi folks,
> For the last few months (after working on a Django app for the first
> time) I've been thinking about adding a first class query concept to
> clj-record. I imagined it might look like this:
>
> (def query (person/make-query))
> (def adult-q (q/add-predicate query :age q/greater-than 17))
> (def draftable-q (q/add-predicate adult-q :sex q/equals "M"))
> (manufacturer/find-all draftable-q))
> ; SELECT * FROM manufacturers WHERE age > 17 AND sex = 'M'
>
> In practice these would most likely be useful in the same way named
> scopes are useful in ActiveRecord, and they could be composable in a
> similar way.
>
> (def males (q/add-predicate (person/make-query) :sex q/equals "M"))
> (def adults (q/add-predicate (person/make-query) :age q/greater-than 17))
> (def draftables (q/compose males adults))
>
> So first, does this seem useful?

yes, this does seem useful. Most of my experience of this kind of
thing has been with the criteria API in Hibernate, and there it's
useful to avoid all the if's and strings that are so verbose and error
prone in Java.

> Next, this isn't an original idea. In fact it's pretty close to some
> things already supported in ClojureQL. What are your thoughts on
> clj-record using ClojureQL as its SQL generator and exposing its query
> API? Looking at the code briefly, I don't think ClojureQL actually
> supports adding predicates to queries right now, but this seems like
> an easy addition. This would have the advantage of giving us easy
> vendor-neutral access to everything those guys have already
> implemented and new clj-record query features for free (or at least
> cheap) as ClojureQL moves forward. (It also means I can throw away my
> least favorite parts of clj-record.)

I am definately in favour of using ClojureQL.

Tunde Ashafa

unread,
Jan 18, 2010, 10:19:11 AM1/18/10
to clj-rec...@googlegroups.com
I'm all for ClojureQL.

Wilson MacGyver

unread,
Jan 18, 2010, 11:13:53 AM1/18/10
to clj-rec...@googlegroups.com
combining efforts like this would lead to faster progress for both projects.
so I think it's a great idea.

On Mon, Jan 18, 2010 at 10:08 AM, John D. Hume <duelin....@gmail.com> wrote:
> ....


> Next, this isn't an original idea. In fact it's pretty close to some
> things already supported in ClojureQL. What are your thoughts on
> clj-record using ClojureQL as its SQL generator and exposing its query
> API? Looking at the code briefly, I don't think ClojureQL actually
> supports adding predicates to queries right now, but this seems like
> an easy addition. This would have the advantage of giving us easy
> vendor-neutral access to everything those guys have already
> implemented and new clj-record query features for free (or at least
> cheap) as ClojureQL moves forward. (It also means I can throw away my
> least favorite parts of clj-record.)
>
> Thoughts?
> -hume.
>
> --
> http://elhumidor.blogspot.com/
>

--
Omnem crede diem tibi diluxisse supremum.

John D. Hume

unread,
Jan 18, 2010, 4:18:29 PM1/18/10
to clj-rec...@googlegroups.com
Glad to hear people are generally in favor of this. Is this just on
principle or have you spent time working or playing with ClojureQL?

Thanks.
-hume.

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

Wilson MacGyver

unread,
Jan 18, 2010, 4:28:42 PM1/18/10
to clj-rec...@googlegroups.com
I must confess, I've only used ClojureQL, and not yet on clj-record.
So far my database connection needs have been limited to pre-existing
tables. And the data sets aren't very large either. So ClojureQL fits
my need.

--

Reply all
Reply to author
Forward
0 new messages