For large result sets, use stream. It returns an async generator that yields rows one at a time as pages are fetched, instead of buffering the whole result in memory.
1
2
3
4
5
6
7
8
const rows = await client.stream<{ id: number }>({
sql: "SELECT id FROM hive.sales.orders",
})
for await (const row of rows) {
process(row)
}
stream accepts the same options as query: transform, impersonateAs, and signal. Aborting the signal stops the generator and throws a TrinoCancellationError on the next pull.