You could just add tests for extra params in OR clauses.

For example, instead of:

(str "SELECT ... main query stuff WHERE basic conditions"
> (when date-range (str " AND dateUpdated >= ? AND dateUpdated < ?"))
> (when qualifier " AND someColumn = ?"))
>

You do this:

SELECT ... main query stuff WHERE basic conditions
AND (? OR dateUpdated >= ? AND dateUpdated < ?
AND (? OR someColumn = ?)

Then instead of delegating to a bunch of different parameters, you just 
supply all the parameters all the time, using dummies where appropriate.

(if date-range
> (if qualifier
> (query-with-date-range-and-qualifier db basic params (first date-range) 
> (second date-range) qualifier)
> (query-with-date-range db basic params (first date-range) (second 
> date-range)))
> (if qualifier
> (query-with-qualifier db basic params qualifier)
> (query-basic db basic params)))
>

Example:

(query db basic params (boolean date-range) (or date-range (now)) (or 
date-range (now)) (boolean qualifier) (or qualifier ""))

You can actually do better than this too, but it will be database specific. 
For the date range example, Postgres has functions that can handle null and 
will optimize your query quite intelligently:

SELECT ... FROM orders WHERE date > GREATEST(MIN(date), ?) AND date < 
LEAST(MAX(date), ?)

That's even better because the query can now specify min and max dates 
separately without a combinatoric explosion of queries.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to