Does hugsql
support lazy sequence of values via a query of against a Postgres backend?
@mafcocinco Getting “lazy sequences” from a database is very problematic because of resource management issues (the connection needs to be open while the sequence is being processed but needs to be closed when you’re done with it — and the sequence has no way of knowing that).
There are ways to stream large result sets from a database, so that the data is read “lazily” from the DB, but to do so you need to eagerly reduce the result set — again so the connection management can do the right thing.
thanks.
Both next.jdbc
and the older clojure.java.jdbc
libraries provide a way to reduce over streaming results. HugSQL can use both of these libraries but I don’t think it exposes any way to leverage the reduce/streaming option, just the full eager processing option. So you’d have to drop down to the underlying library to do that.
See, for example, https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.1.643/doc/getting-started/tips-tricks#streaming-result-sets-1 which talks about PostgreSQL and streaming result sets.