;; 命令是修改数据,而不是查询数据。这里没有 JDBC 驱动,
;; 但修改本身就是作用于各行的函数:它返回新值,旧值保持不变
(def city
[{:id 1 :name "Kabul" :country-id 1}
{:id 2 :name "Qandahar" :country-id 1}
{:id 3 :name "Utrecht" :country-id 7}])
;; delete from city where country_id = 7
(def city-left (remove #(= 7 (:country-id %)) city))
(println "was" (count city) "rows, now" (count city-left))
(doseq [c city-left]
(println (:id c) (:name c)))
;; 最初的那些行仍在,没有任何数据被原地修改
(println "original still holds" (count city) "rows")
;; 类路径上有 next.jdbc 时,同样的命令只需一次调用,
;; 它返回所影响的行数:
;; (jdbc/execute-one! ds ["delete from city where country_id = ?" 7])