fix(react-native): decode op-sqlite results losslessly - #1848
KyleAMathews wants to merge 5 commits into
Conversation
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe driver now decodes op-sqlite columnar ChangesOp-SQLite result decoding
Priority: ⬆️ High Estimated code review effort: 4 (Complex) | ~45 minutes Change: Bug fix · Severity of issue fixed: High Sequence Diagram(s)sequenceDiagram
participant Persistence
participant OpSQLiteDriver
participant executeAsync
participant SQLiteDatabase
Persistence->>OpSQLiteDriver: query collection_registry
OpSQLiteDriver->>executeAsync: execute SQL
executeAsync->>SQLiteDatabase: read registry rows
SQLiteDatabase-->>executeAsync: rawRows and columnNames
executeAsync-->>OpSQLiteDriver: columnar result envelope
OpSQLiteDriver-->>Persistence: decoded registry row
Persistence->>OpSQLiteDriver: load persisted subset
OpSQLiteDriver-->>Persistence: decoded persisted rows
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/react-router-with-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: 0 B Total Size: 165 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 7.34 kB ℹ️ View Unchanged
|
This fixes silent SELECT data loss in the React Native SQLite adapter by decoding op-sqlite v14 columnar results into exact object rows. Malformed or unknown result envelopes now fail with a configuration error, while persisted rows, registry identity, and stream position remain intact across restart.
Reviewer guidance
Root cause
OpSQLiteDriverunderstood direct row arrays androws-style wrappers, but op-sqlite v14 can returnexecuteAsyncresults as{ rawRows, columnNames, rowsAffected }. The old extraction path did not reconstruct those rows and could normalize an unrecognized SELECT result to an empty result, making real data appear to disappear.Approach
rawRowsentry withcolumnNames, preserving column order, aliases, row order, values, and multiplicity.resultswrapper distinct at the outer result boundary.InvalidPersistedCollectionConfigError.Key invariants
rows,rawRows, androwsAffectedremain ordinary row data.Non-goals and trade-offs
Verification
Verified locally with 112/112 React Native persistence tests and 96/96 SQLite core tests passing, plus the exact seed/path replay, both package builds and typechecks, all shared SQLite-driver consumers, formatting, lint (zero errors), diff, and cleanup checks.
Files changed
packages/react-native-db-sqlite-persistence/src/op-sqlite-driver.ts— strictly classifies and decodes supported op-sqlite result envelopes.packages/react-native-db-sqlite-persistence/tests/helpers/op-sqlite-test-db.ts— adds a v14-styleexecuteAsynccolumnar fixture.packages/react-native-db-sqlite-persistence/tests/op-sqlite-driver.test.ts— adds fixed witnesses, generated alias histories, malformed-envelope controls, replay, and cleanup assertions.packages/react-native-db-sqlite-persistence/tests/react-native-persistence.test.ts— verifies pre-populated registry reuse and exact row/stream restoration after close and reopen.packages/db-sqlite-persistence-core/tests/contracts/sqlite-driver-contract.ts— adds exact write-then-read and reserved-alias laws across shared drivers..changeset/fix-op-sqlite-result-decoding.md— records the React Native persistence patch.Fixes #1499
Part of #1659
Summary by CodeRabbit