Created
September 8, 2014 18:10
-
-
Save ghadishayban/d2f31961deba98ee4595 to your computer and use it in GitHub Desktop.
result sets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn result-set | |
[^ResultSet rs & {:keys [identifiers] | |
:or {identifiers str/lower-case}}] | |
(reify clojure.lang.IReduce | |
(reduce [this f] | |
(reduce [this f (f)])) | |
(reduce [this f init] | |
(let [rsmeta (.getMetaData rs) | |
idxs (range 1 (inc (.getColumnCount rsmeta))) | |
col (fn [^Integer i] | |
(.getColumnLabel rsmeta i)) | |
val (fn [^Integer i] | |
(-> rs | |
(.getObject i) | |
(result-set-read-column rsmeta i))) | |
keys (->> (map col idxs) | |
make-cols-unique | |
(map (comp keyword identifiers)))] | |
(loop [ret init] | |
(if (.next rs) | |
(let [ret (f ret (zipmap keys (map val idxs)))] | |
(if (reduced? ret) | |
@ret | |
(recur ret))) | |
ret)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment