hugsql
hugsql copied to clipboard
Question: lazy result set
With postgresql (probably other databases as well) you can set the fetch-size on a statement to the result set will not be pulled in 1 go into the client. This is useful if you have large result sets you need to process record by record. With plain clojure.java.jdbc you would do that like
(jdbc/with-db-transaction [tx connection]
(jdbc/query tx
[(jdbc/prepare-statement (:connection tx)
"select * from tablewithmanyrecords"
{:fetch-size 10})]
{:result-set-fn (fn [result-set] ...)}))
https://jdbc.postgresql.org/documentation/94/query.html#query-with-cursor
It's a bit unclear how I would do something similar with hugsql.
+1 does hugsql have any support for cursors?
Would also like to know the answer to this question.
+1
+1
Any news on this feature?
This works for me, given a sqlvec-query
and side-effecting-fn
to do something with each result.
(jdbc/with-db-transaction [tx *db*]
(let [results (jdbc/reducible-query tx sqlvec-query {:fetch-size 1000})]
(transduce (map side-effecting-fn) (constantly nil) results)))