I would like to be able to build the where clauses for a query. I would like to input a array of where conditions and build the query using korma, as seen below:
(defn ^:private fetch-by
"Append conditions to the query."
[query ^clojure.lang.PersistentVector conditions]
(for [condition conditions]
(if (instance? clojure.lang.PersistentArrayMap condition)
(korma/where query condition) query)))
However, the for loop here will duplicate the query object. Is there away to merge these objects or another approach you can recommend that would achieve the desired output?
The merging of the
conditionsinto one query map can be done withreduce:Here your initial
reducestate is whateverqueryyou pass in, and the reducing function (andkorma/where) take care of merging each condition into the query map.However this is not really different than just passing a single map with multiple entries to
korma/where:which I would suggest as long as the conditions' keys are unique.