import { Knex } from 'knex' export const scanTableFactory = ({ db }: { db: Knex }) => async function* ({ tableName, batchSize }: { tableName: string; batchSize: number }) { const [rowsCount] = await db(tableName).count() const MAX_LIMIT = parseInt(rowsCount.count.toString()) let offset = 0 while (offset <= MAX_LIMIT) { yield db(tableName).limit(batchSize).offset(offset) offset += batchSize } }