Closed lynaghk closed 12 years ago
Maybe select-if does what you want? https://github.com/LauJensen/clojureql/blob/master/src/clojureql/core.clj#L243
Yes, that is exactly what I want. I feel pretty silly having missed it, thanks for pointing it out.
It's not yet documented, so no worries.
I caught myself throwing around a lot of
if
andstr
trying to handle optional predicates earlier today, but since that makes Danish and relational algebra-loving kittens mew sadly, I'm trying to find nicer ways to handle the situation.Maybe the simplest would be to silently discard predicates with nil arguments:
Currently the output is
where our non-nil predicate has slipped over to the wrong spot in the prepared statement. This would make the calling code very simple, at the risk of silently dropping predicates you actually want sometimes.
So far, I've been writing my ClojureQL code in the chained style:
and I guard against nil predicates using an ugly anonymous function:
which I'm thinking about abstracting into a macro, but I'd like to get your opinions first. How do you all handle this issue? Should it be handled in the calling code or magically taken care of in the ClojureQL library code?