1

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.

4

2 回答 2

3

where功能仅支持=比较。你可以做的是代替(s/where {..})你可以放置一个代表查询部分的向量:["cost > ? AND cost < ?" 22 44]

于 2013-05-23T12:40:09.413 回答
0

由于 SQL DSL 已从 中删除clojure.java.jdbc,因此推荐的方法是对 DSL 使用HoneySQL(如 README 中所述clojure.java.jdbc)。

于 2018-05-31T05:09:01.697 回答