Skip to content

feat: expose lazy rows on managed SQLite queries - #541

Draft
chrispader wants to merge 5 commits into
feat/398-lazy-row-conversionfrom
feat/398-managed-lazy-queries
Draft

chrispader wants to merge 5 commits into
feat/398-lazy-row-conversionfrom
feat/398-managed-lazy-queries

Conversation

@chrispader

@chrispader chrispader commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

When a screen reads only a few rows from a large result, the managed eager API still converts every row. Use executeLazy or executeLazyAsync to get cached rows on demand through rows.item(index) and convert the entire result with rows.toArray(). These methods follow the managed connection and transaction queues and work with prepared statements.

const { rows } = await db.executeLazyAsync('SELECT id, title FROM notes ORDER BY id')
const first = rows.item(0)

Builds on #537.

Part of #398

Reviewed with sol-loop: 2 rounds with gpt-6.2-sol on high. Sol verdict: approved.

Note

🤖 Generated with Codex

@vercel

vercel Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
react-native-nitro-sqlite Ready Ready Preview Dec 4, 2026 4:11pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 30, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@chrispader chrispader left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Chris's AI partner in code reporting in (Claude Opus 5.5). 🤖

The code is consistent, but it shouldn't close #398 yet: the benchmark doesn't show a benefit, and the docs are incomplete. I reviewed this PR and Callstack's Apex model reviewed it separately. Neither of us found a code bug. The managed lazy paths go through the same queue, pending-async tracking and error normalization as executeAsync. Prepared statements wrap errors the same way, and the Node mock matches native.

  • "Fixes #398" isn't backed by numbers yet. The issue asks to compare first-row latency, partial and full reads, and peak native and JS memory on Release devices. These cases measure latency only, and neither PR body reports results. Post the Release results with memory, or change the link to "Part of #398". (Claude, inline)
  • The memory figures depend on GC timing. run() drops rows but never forces a collection, and the runner calls it 11 times back to back. So each lazy run's ~100k unconverted rows can stay registered as external memory, and peakBytes for read-lazy-first and read-lazy-partial can include earlier runs. Add a reset that yields or collects between runs, or say that these peaks depend on GC timing. (Apex, inline)
  • The guides that list the query methods leave out the lazy ones. transactions.mdx (lines 32, 42 and 60) and prepared-statements.mdx:6 still list four query methods. The pending-async rule at transactions.mdx:60 leaves out tx.executeLazyAsync(), even though tx.commit() throws while one is pending. transaction.ts:48 and mock/transaction.ts:20 still tell users to "Await all tx.executeAsync calls first". (Apex)
  • The shape of lazy rows is undocumented. rows only has length, item() and toArray(). for…of and spreading fail with "rows is not iterable". JSON.stringify(result) silently writes {"rows":{"length":100000}}, where the eager result serialized fully. TypeScript catches iteration, but not the JSON case or code ported from the rows._array example 20 lines above. One sentence in the new section would cover it. (Apex, inline)
  • Adding required interface members is a type-level break. The new methods are required on NitroSQLiteConnection, Transaction and PreparedStatement, so user test doubles typed as those interfaces stop compiling on a minor release. Please mention it in the release announcement. Also, docs/scripts/check-api.mjs doesn't pin executeLazy, executeLazyAsync, LazyQueryResult or LazyQueryRows. (Apex)

The device spec, executeLazy.spec.ts, hasn't run on this draft: only Fast checks ran.

@@ -102,6 +103,14 @@ export const readCases: BenchmarkCase[] = [
label: '10k narrow rows · raw arrays read + access',
setup: setupNarrowRawRead,
},
...(['first', 'partial', 'full'] as const).flatMap((access) =>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude (medium): These cases measure latency only. #398 also asks for peak native and JS memory on Release devices, and no numbers are posted yet. Post those results before closing the issue, or change the PR to "Part of #398".

rowCount = rows.length
if (access === 'full') {
const all = '_array' in rows ? rows._array : rows.toArray()
assertBenchmark(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex: Nothing collects between the 11 back-to-back runs, so unconverted lazy rows from earlier runs can still count as external memory when peakBytes is sampled. Yield or collect between runs, or note that the first-row and partial peaks depend on GC timing.


```ts
const { rows } = await db.executeLazyAsync<{ id: number; name: string }>(
'SELECT id, name FROM people WHERE age >= ? ORDER BY id',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex: Please say that lazy rows only offer length, item() and toArray(): no index access, no iteration, and no _array, and that JSON.stringify(result) doesn't include the rows. The eager example just above uses rows._array, so readers will try the same here.

@@ -66,6 +70,10 @@ export interface NitroSQLiteConnection {
execute: ExecuteQuery
/** Queue one SQL statement and resolve with its result. */
executeAsync: ExecuteAsyncQuery
/** Execute one statement synchronously with on-demand row conversion. Throws while the connection is busy. */
executeLazy: ExecuteLazyQuery

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex (low): Making these members required breaks user code that implements NitroSQLiteConnection, Transaction or PreparedStatement, such as test doubles. That's fine for this feature, but worth naming in the release announcement.

chrispader and others added 5 commits December 4, 2026 17:09
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>

This branch was successfully deployed

1 active deployment
Preview — 212aac00 Deployed Dec 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant