Skip to content

Commit

Permalink
[jdbc.row] Replace memoize in lazy thunk construction with delays (#192)
Browse files Browse the repository at this point in the history
* [jdbc.row] Replace memoize in lazy thunk construction with delays

* Update src/toucan2/jdbc/read.clj

---------

Co-authored-by: Cam Saul <[email protected]>
  • Loading branch information
alexander-yakushev and camsaul authored Nov 6, 2024
1 parent a341f76 commit edee4e0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/toucan2/jdbc/read.clj
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,13 @@
(defn ^:no-doc make-i->thunk
"Given a connection `conn`, a `model` and a result set `rset`, return a function which given a column number `i` returns
a thunk that retrieves the column value of the current row from the result set."
[conn model rset]
(comp (memoize (fn [i]
(make-column-thunk conn model rset i)))
int))
[conn model ^ResultSet rset]
(let [n (.getColumnCount (.getMetaData rset))
thunks (mapv (fn [i]
(delay (make-column-thunk conn model rset (inc i))))
(range n))]
(fn [i]
@(nth thunks (dec i)))))

(defn ^:no-doc read-column-by-index-fn
"Given a `i->thunk` function, return a function that can be used with [[next.jdbc.result-set/builder-adapter]]. The
Expand Down

0 comments on commit edee4e0

Please sign in to comment.