This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-13
Channels
- # ai (5)
- # announcements (4)
- # babashka (34)
- # beginners (78)
- # biff (6)
- # calva (41)
- # cider (47)
- # clerk (1)
- # clj-commons (3)
- # clj-http (1)
- # clojure (72)
- # clojure-europe (51)
- # clojure-nl (1)
- # clojure-norway (87)
- # clojure-romania (1)
- # clojure-uk (5)
- # clojuredesign-podcast (2)
- # community-development (1)
- # conjure (2)
- # cursive (11)
- # datomic (6)
- # docker (4)
- # emacs (13)
- # exercism (20)
- # hyperfiddle (56)
- # matrix (6)
- # membrane (4)
- # nbb (11)
- # off-topic (88)
- # pathom (7)
- # pedestal (1)
- # polylith (20)
- # portal (16)
- # practicalli (1)
- # re-frame (13)
- # reagent (4)
- # reitit (2)
- # remote-jobs (7)
- # shadow-cljs (49)
- # sql (4)
Hi All, I'm using next.jdbc to query a db and dump the results right into a csv, so I don't want keyword column names. Is this a reasonable way to implement the result set builder to get string column names?
(require '[next.jdbc.result-set :as rs])
(import '(java.sql ResultSet ResultSetMetaData))
(defn get-string-column-names
"Given `ResultSetMetaData`, return a vector of string column names."
[^ResultSetMetaData rsmeta _]
(mapv (fn [^Integer i] (str (.getColumnLabel rsmeta i)))
(range 1 (inc (if rsmeta (.getColumnCount rsmeta) 0)))))
(defn as-string-arrays
"Given a `ResultSet` and options, return a `RowBuilder` / `ResultSetBuilder`
that produces a vector of simple string column names followed by vectors of row
values."
[^ResultSet rs opts]
(let [rsmeta (.getMetaData rs)
cols (get-string-column-names rsmeta opts)]
(rs/->ArrayResultSetBuilder rs rsmeta cols)))
It's working, I just want to be sure this is the right what to go about this.The better approach would be to use CopyManager that redirects the result into an OutputStream. It's much faster than selecting the data in memory and write them to CSV manually