Korma SQL クエリに WHERE 条件を動的に追加しようとしています
(-> 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 の初心者です