fix(db): support INT2/INT4/INT8 array deserialization (#27)#35
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR resolves issue ChangesInteger Array Support for PostgreSQL Results
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 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 |
The patched tauri-plugin-sql added several Postgres array decoders but the integer-array widths (INT2[], INT4[], INT8[]) fell through to the catch-all fallback that tries Vec<String>, which sqlx refuses to decode, so the result deserializer crashed with 'unsupported datatype: _INT4' the moment a query returned an int[] column. Add explicit match arms for INT2[], INT4[], INT8[] in decode/postgres.rs. Each decodes as Vec<Option<T>> so SQL NULL elements survive as JSON null, and emits each element via JsonValue::Number — mirroring the scalar INT2 / INT4 / INT8 arms above them. INT8 uses the same straight i64 -> Number cast the scalar arm uses; JS consumers needing full 64-bit precision parse through their existing bignum path (Number.MAX_SAFE_INTEGER is 2^53, so larger values round-trip through serde_json::Number losslessly). Tests: new #[cfg(test)] module in decode/postgres.rs covering each width at type bounds, the >2^53 INT8 case, NULL elements, and the empty-array case. This is also the first Rust test landed in the patched plugin, so it bootstraps the test backfill flagged in CLAUDE.md / issue #24. Smoke script: dev/test-db/test-scripts/07-int-arrays.sql, runnable against the existing dev/test-db Postgres on localhost:5434. README updated. Closes #27
d18fdf1 to
e39e0d9
Compare
Closes #27
Root cause
The patched
tauri-plugin-sql(src-tauri/patches/tauri-plugin-sql/src/decode/postgres.rs) carries explicit match arms for several Postgres array shapes but not for integer arrays.INT2[],INT4[], andINT8[]fell through to the catch-all fallback, which triesVec<String>first — sqlx refuses to decode an integer array asVec<String>, so the next branch returnedError::UnsupportedDatatype("_INT4")and the whole result set failed to deserialize.Changes
src-tauri/patches/tauri-plugin-sql/src/decode/postgres.rs"INT2[]","INT4[]","INT8[]". Each decodes asVec<Option<T>>(so SQLNULLelements survive as JSONnull) and emits each element viaJsonValue::Number, mirroring the scalarINT2/INT4/INT8arms above them.INT8[]uses the same straighti64→serde_json::Numbercast the scalarINT8arm uses — no new "big int" convention invented. JS consumers needing full 64-bit precision parse through the same bignum path they already use for scalarBIGINT.int_vec_to_json<T: Into<serde_json::Number>>helper to keep the three arms identical.#[cfg(test)] mod tests— this is the first Rust test landed in the patched plugin, so it bootstraps the test backfill flagged inCLAUDE.mdand issue Testing infrastructure roadmap #24.dev/test-db/test-scripts/07-int-arrays.sql— copy-paste smoke script against the existingdev/test-dbPostgres onlocalhost:5434. Covers basic dense arrays, type bounds, negatives,NULLelements, and a value beyondNumber.MAX_SAFE_INTEGER(1::int8 << 60).dev/test-db/README.md— new row in the test-scripts table.CHANGELOG.md— entry under## [Unreleased]→### Fixed.Test plan
cargo build(fromsrc-tauri/) — clean.cargo test --features postgres(from the patch dir) — 5/5 new tests pass: bounds for INT2/INT4, full i64 range for INT8 including1 << 60, NULL-element preservation, empty-array case.cargo clippy -- -D warnings(fromsrc-tauri/) — clean.npm test— 52/52 passing.npx tsc --noEmit— clean.docker compose up -dindev/test-db/, connect QueryDen tolocalhost:5434, paste07-int-arrays.sql, run with Ctrl+Enter. Both rows render and each integer-array column displays a JSON array of numbers with thenullelement preserved in the second row.Constraints respected
tauri-plugin-sqlversion insrc-tauri/Cargo.tomlis not bumped — only the patch is modified.Summary by CodeRabbit