ReviewOS

stacks/bun-query-builder

Snapshot-consistent paginate() via optional transaction

#1051
Closed glennmichael123 opened this 2 months ago ·
2 months ago

Summary

paginate() runs COUNT and the page query as two separate statements; an inline comment documents the known race (total/data inconsistency under concurrent writes) and explicitly defers a tx parameter "to a future major version." Accept an optional { tx } (the transaction machinery already exists) so callers can opt into snapshot isolation.

Effort: S–M. Location: src/client.ts:~4533. Fixes a self-documented correctness gap. Found via internal code audit.

9 days ago

Done in d836ca1. paginate(perPage, page, { tx }) now routes both the COUNT and the page-data through the caller-supplied transaction handle, so they read one consistent snapshot and total can't desync from data.length under concurrent writes (resolves the long-standing TODO in the code). The caller owns the transaction + isolation level; omitting tx keeps the existing back-to-back behaviour. Tests cover tx routing + real-sqlite correctness; full suite green.

Sign in to comment on this issue.