You don't need the transaction and prepared-statement stuff above. It is the use of :result-set-fn
that causes the lazy-sequence to be consumed. You may have meant to use :row-fn
instead.
For full details please see The Clojure Cookbook. A print version is also available, which I recommend.
The jdbc/query function has several optional keyword parameters that
control how it constructs the returned result set. The :result-set-fn
parameter specifies a function that is applied to the entire result
set (a lazy sequence) before it is returned. The default argument is
the doall function:
(defn hi-lo [rs] [(first rs) (last rs)])
;; Find the highest- and lowest-cost fruits
(jdbc/query db-spec
["select * from fruit order by cost desc"]
:result-set-fn hi-lo)
;; -> [{:grade nil, :unit nil, :cost 77, :appearance nil, :name "Kumquat"}
;; {:grade 1.4, :unit nil, :cost 10, :appearance "rotten", :name "Tomato"}]
The :row-fn parameter specifies a function that is applied to each
result row as the result is constructed. The default argument is the
identity function:
(defn add-tax [row] (assoc row :tax (* 0.08 (row :cost))))
(jdbc/query db-spec
["select name,cost from fruit where cost = 12"]
:row-fn add-tax)
;; -> ({:tax 0.96, :cost 12, :name "Plum"} {:tax 0.96, :cost 12, :name "Fig"})