I am trying to generate korma query conditions based on a map of columns and values that I pass into a function.
I am finding that when an empty map is passed to korma's where:
(select "things"
(where conditions))
Generates queries with an empty WHERE which causes a SQL error:
SELECT * FROM things WHERE () LIMIT 10
However using this form:
(select "things"
(if-not (empty? conditions)
(where conditions)))
Results in an error: "Wrong number of args (1) passed to: core$where"
Is there an idiomatic way of handling dynamic clauses in korma?
UPDATE
The following works, but is pretty clumsy (note the strangely necessary if format)
(defn do-select []
(-> (select* "things")
(fields :id :data)
(limit 10)))
(defn add-constraints [query conditions]
(if (empty? conditions)
query
(where query (conditions-to-clause-map conditions))))
(select (do-select)
(add-constraints conditions)
(where (is_owner? owner)))