Reputation: 1070
How can I implement select * from fruit where cost > 22 and cost < 44 w/ DSL way, by example below from clojure/java.jdbc demo:
(require '[clojure.java.jdbc :as j]
'[clojure.java.jdbc.sql :as s])
(def mysql-db {:subprotocol "mysql"
:subname "//127.0.0.1:3306/clojure_test"
:user "clojure_test"
:password "clojure_test"})
(j/insert! mysql-db :fruit
{:name "Apple" :appearance "rosy" :cost 24}
{:name "Orange" :appearance "round" :cost 49})
;; ({:generated_key 1} {:generated_key 2})
(j/query mysql-db
(s/select * :fruit (s/where {:appearance "rosy"}))
:row-fn :cost)
;; (24)
Thanks in advance.
Upvotes: 1
Views: 1308
Reputation: 6666
Since the SQL DSL has been removed from clojure.java.jdbc
, the recommended approach is to use HoneySQL for the DSL (as explained in the README for clojure.java.jdbc
).
Upvotes: 0
Reputation: 33637
The where
function only supports =
comparison. What you can do is instead of (s/where {..})
you can put a vector which represent the query part: ["cost > ? AND cost < ?" 22 44]
Upvotes: 3