我正在尝试将 WHERE 条件动态添加到 Korma SQL 查询
(-> the-query
(where {:archived false})
(add-where-conditions params)
(limit 200)
(select))
我正在尝试动态构建对 korma 的where函数的调用。调用看起来像(where query (or (between :freq [100 200]) (between :freq [300 400]) ... ))
. 辅助函数make-conds列出了where函数的参数,例如:(or (between :freq [100 200]) ...
我尝试了以下方法来构建动态 where 调用。只有第一个,有eval
作品的。为什么?有一个更好的方法吗?
(defn add-where-conditions [query params]
(eval (list 'where query (make-conds params))))
(defmacro add-where-conditions-2 [query params]
(list 'where query (make-conds params))) ; broken
(defmacro add-where-conditions-3 [query params]
`(where ~query ~(make-conds params))) ; broken
免责声明:我是 Clojure 和 Korma 的新手