Fork me on GitHub

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.


Both next.jdbc and the older 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.