(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.
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.
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.
Thanks.
-hume.
--