I would like to be able to build one query which takes a string of uuid's and spiting it out by commas to generate the following sql statement:
uuid
4506ef72-aa17-452b-9456-38d11c71897b,bd46629d-0e8c-4d70-874a-76bfade8ef14,b0c11580-7cde-4a4e-ba0a-30f9de52e3b5
sql
SELECT * FROM my-table WHERE uuid="4506ef72-aa17-452b-9456-38d11c71897b" OR bd46629d-0e8c-4d70-874a-76bfade8ef14 OR b0c11580-7cde-4a4e-ba0a-30f9de52e3b5 ORDER BY created DESC;
I have attempted generating this query using sqlkorma in the following method, however I am having a problem generating the WHERE clause.
(defn fetch [uuid]
(->
(korma/select* :my-table)
(korma/order :created :DESC)
(as-> query
(if (not= uuid nil)
(for [id (str/split uuid #",")]
(korma/where query {:uuid id}))
query))
(korma/query-only))
)
Give this a try:
Instead of
OR-ing the conditions, this usesIN.