1

有谁知道如何做到这一点?

(get-lists ["free" "food"])->

Select name 
From Lists
Where name like '%free%' and name like '%food%'

我努力了:

-- :name get-lists :? :*
Select id, name
from Lists
where
--~ (clojure.string/join "" (interpose " AND " (map #(str "name LIKE '%" % "%'") :sKeyWords)))

但这当然行不通。有人可以指出我正确的方向吗?

4

2 回答 2

2

要形成查询,您还可以使用clojure 标准库中的clojure.pprint/cl-format,它非常强大且简洁:

user> (require '[clojure.pprint :refer [cl-format]])

user> (cl-format nil "WHERE~{ name LIKE '%~a%' ~^AND~}" 
                 ["me" "you" "somebody"])
;;=> "WHERE name LIKE '%me%' AND name LIKE '%you%' AND name LIKE '%somebody%' "
于 2020-04-22T14:37:05.630 回答
1

想出了答案。放在这里给任何可能需要它的人。

-- :name get-lists :? :*
Select id, name
from Lists
--~ (str "WHERE " 
        (clojure.string/join " AND " (map #(str "name LIKE '%" % "%'") 
          (:key-words params))))
于 2020-04-21T19:22:24.890 回答