I'm curious as to how folks using Yesql deal with conditional queries - which is something we seem to run into a lot.
For example, we have some business logic that might optionally be passed a date
range and maybe some other qualifier so our query would be:
(str "SELECT ... main query stuff WHERE basic conditions"
(when date-range (str " AND dateUpdated >= ? AND dateUpdated <
?"))
(when qualifier " AND someColumn = ?"))
and then some conditions to build the parameters:
(cond-> basic-params
date-range (concat date-range)
qualifier (concat [qualifier]))
It seems like with Yesql we'd have to have four different query functions and
then code like this:
(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)))
Sean
On Jul 22, 2014, at 6:08 AM, Timothy Baldridge <[email protected]> wrote:
> Also, read the rationale behint yesql: https://github.com/krisajenkins/yesql
> IMO, it hits the nail on the head. ORMs are both crappy object systems and
> crappy DB DSLs. With a library like yesql you write your queries in pure SQL
> and get pure data back. Now you can fully leverage both SQL and Clojure.
signature.asc
Description: Message signed with OpenPGP using GPGMail
