K
Kysely4mo ago
bun

Why does `.stream()` return a single result when I pass in a `chunkSize` option ?

I'm guessing it returns chunkSize mount of rows for each iteration, but shouldn't it be an array instead?
1 Reply
bun
bun4mo ago
I guess I'm obligated to do something like this:
const events = db.selectFrom("events").selectAll().stream(10_000)

let currChunk = [] as Events[]

for await (const chunk of events) {
currChunk.push(chunk)

if (currChunk.length === 10_000) {
// process chunk

currChunk = []
}
}
const events = db.selectFrom("events").selectAll().stream(10_000)

let currChunk = [] as Events[]

for await (const chunk of events) {
currChunk.push(chunk)

if (currChunk.length === 10_000) {
// process chunk

currChunk = []
}
}