You're viewing version 1.2.0 of resultset-seq. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

resultset-seq

clojure.core

  • (resultset-seq rs)
Creates and returns a lazy sequence of structmaps corresponding to
the rows in the java.sql.ResultSet rs

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:4537 top

(defn resultset-seq
  "Creates and returns a lazy sequence of structmaps corresponding to
  the rows in the java.sql.ResultSet rs"
  {:added "1.0"}
  [^java.sql.ResultSet rs]
    (let [rsmeta (. rs (getMetaData))
          idxs (range 1 (inc (. rsmeta (getColumnCount))))
          keys (map (comp keyword #(.toLowerCase ^String %))
                    (map (fn [i] (. rsmeta (getColumnLabel i))) idxs))
          check-keys
                (or (apply distinct? keys)
                    (throw (Exception. "ResultSet must have unique column labels")))
          row-struct (apply create-struct keys)
          row-values (fn [] (map (fn [^Integer i] (. rs (getObject i))) idxs))
          rows (fn thisfn []
                 (when (. rs (next))
                   (cons (apply struct row-struct (row-values)) (lazy-seq (thisfn)))))]
      (rows)))
Vars in clojure.core/resultset-seq: defn let
Used in 1 other vars with-query-results*

Comments top

No comments for resultset-seq. Log in to add a comment.