hugsql

mafcocinco 2021-03-30T20:17:52.001200Z

Does hugsql support lazy sequence of values via a query of against a Postgres backend?

seancorfield 2021-03-30T20:21:04.002400Z

@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).

seancorfield 2021-03-30T20:22:33.003600Z

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.

mafcocinco 2021-03-30T20:22:59.004100Z

thanks.

seancorfield 2021-03-30T20:24:40.006Z

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.

seancorfield 2021-03-30T20:25:39.006400Z

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.