This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-18
Channels
- # announcements (35)
- # babashka (31)
- # beginners (77)
- # biff (23)
- # calva (1)
- # clj-kondo (4)
- # cljsrn (3)
- # clojure (71)
- # clojure-dev (9)
- # clojure-europe (51)
- # clojure-france (3)
- # clojure-germany (1)
- # clojure-nl (3)
- # clojure-spec (9)
- # clojure-uk (42)
- # clojurescript (24)
- # clojureverse-ops (3)
- # component (16)
- # cursive (1)
- # data-science (8)
- # emacs (1)
- # fulcro (5)
- # graalvm-mobile (1)
- # graphql (2)
- # honeysql (36)
- # leiningen (3)
- # malli (3)
- # off-topic (16)
- # remote-jobs (1)
- # sql (3)
- # testing (19)
- # tools-deps (11)
- # xtdb (20)
@ben.sless If you really need to optimize fetching stuff to the point that you can't use map->SomeRecordType
, have you considered just writing your own low-level code to fetch the rows from the ResultSet
in this case? I think that would be a little easier and faster than the big macro to reify RowBuilder
and ResultSetBuilder
. If you know what columns are coming back you can avoid the overhead of having to programatically figure that out via the ResultSetMetaData
, the calls to read-column-by-index
, etc. e.g.
(defrecord Person [id name])
(defn reducible-people-results [^java.sql.ResultSet rs]
(reify
clojure.lang.IReduceInit
(reduce [_ rf init]
(loop [acc init]
(cond
(reduced? acc) acc
(.next rs) (recur (rf acc (->Person
(.getInt rs "id")
(.getString rs "name"))))
:else acc)))))
(toucan2.conn/with-connection [conn :test/postgres]
(with-open [stmt (.prepareStatement conn "SELECT id, name FROM people;")
rset (.executeQuery stmt)]
(reduce
conj
[]
(reducible-people-results rset))))
;; ->
[#Person{:id 1, :name "Cam"}
#Person{:id 2, :name "Sam"}
#Person{:id 3, :name "Pam"}
#Person{:id 4, :name "Tam"}]
Normally I wouldn't advocate writing such low-level JDBC code but if you're at the point you don't want to use the map->Record
fn because of overhead then it might be time to tune stuff a little further👏 3