Skip to content

fix(db): support INT2/INT4/INT8 array deserialization (#27)#35

Merged
openidle-dev merged 1 commit into
mainfrom
fix/27-int-array-deserializer
May 14, 2026
Merged

fix(db): support INT2/INT4/INT8 array deserialization (#27)#35
openidle-dev merged 1 commit into
mainfrom
fix/27-int-array-deserializer

Conversation

@openidle-dev

@openidle-dev openidle-dev commented May 14, 2026

Copy link
Copy Markdown
Owner

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[], and INT8[] fell through to the catch-all fallback, which tries Vec<String> first — sqlx refuses to decode an integer array as Vec<String>, so the next branch returned Error::UnsupportedDatatype("_INT4") and the whole result set failed to deserialize.

Changes

  • src-tauri/patches/tauri-plugin-sql/src/decode/postgres.rs
    • New explicit arms for "INT2[]", "INT4[]", "INT8[]". 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 i64serde_json::Number cast the scalar INT8 arm uses — no new "big int" convention invented. JS consumers needing full 64-bit precision parse through the same bignum path they already use for scalar BIGINT.
    • New int_vec_to_json<T: Into<serde_json::Number>> helper to keep the three arms identical.
    • New #[cfg(test)] mod tests — this is the first Rust test landed in the patched plugin, so it bootstraps the test backfill flagged in CLAUDE.md and issue Testing infrastructure roadmap #24.
  • dev/test-db/test-scripts/07-int-arrays.sql — copy-paste smoke script against the existing dev/test-db Postgres on localhost:5434. Covers basic dense arrays, type bounds, negatives, NULL elements, and a value beyond Number.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 (from src-tauri/) — clean.
  • cargo test --features postgres (from the patch dir) — 5/5 new tests pass: bounds for INT2/INT4, full i64 range for INT8 including 1 << 60, NULL-element preservation, empty-array case.
  • cargo clippy -- -D warnings (from src-tauri/) — clean.
  • npm test — 52/52 passing.
  • npx tsc --noEmit — clean.
  • Manual: docker compose up -d in dev/test-db/, connect QueryDen to localhost:5434, paste 07-int-arrays.sql, run with Ctrl+Enter. Both rows render and each integer-array column displays a JSON array of numbers with the null element preserved in the second row.

Constraints respected

  • tauri-plugin-sql version in src-tauri/Cargo.toml is not bumped — only the patch is modified.

Summary by CodeRabbit

Review Change Stack

@vercel

vercel Bot commented May 14, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
queryden Ready Ready Preview, Comment May 14, 2026 7:13am

@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1f5b7bf3-65e8-4fc6-acd5-eca3208e052a

📥 Commits

Reviewing files that changed from the base of the PR and between 1d9fae8 and e39e0d9.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • dev/test-db/README.md
  • dev/test-db/test-scripts/07-int-arrays.sql
  • src-tauri/patches/tauri-plugin-sql/src/decode/postgres.rs

📝 Walkthrough

Walkthrough

This PR resolves issue #27 by implementing explicit JSON deserialization for PostgreSQL integer array types (INT2[], INT4[], INT8[]). The fix adds decode branches in the patched tauri-plugin-sql decoder, a helper function to convert nullable integer vectors to JSON, and validates the behavior with a SQL test and documentation updates.

Changes

Integer Array Support for PostgreSQL Results

Layer / File(s) Summary
Integer array JSON decoding
src-tauri/patches/tauri-plugin-sql/src/decode/postgres.rs
Adds three to_json match arms for INT2[], INT4[], INT8[] that decode each as Vec<Option<integer>> so SQL null elements become JSON null. Introduces a shared private helper int_vec_to_json<T> that converts Some(n) to JsonValue::Number and None to JsonValue::Null without lossy float handling. Unit tests verify correct element mapping, empty array handling, null preservation, and INT8[] behavior for values beyond JavaScript safe-integer range.
Integration test and documentation
dev/test-db/test-scripts/07-int-arrays.sql, CHANGELOG.md, dev/test-db/README.md
Adds a comprehensive SQL test script that drops/recreates app.int_arrays, populates it with int2[], int4[], int8[] columns (including NULLs, boundary values, and over-safe-integer BIGINT cases), and performs ordered SELECT to exercise the deserialization path. Documents the test in the test-db README and records the fix in CHANGELOG.md with a description of the decoding behavior and reference to the smoke test.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

🐰 Arrays of integers lost and found,
Now deserialize without a sound!
NULL elements dance as JSON null,
INT8 precision survives it all,
The rabbit hops—the fix is round!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title is concise and clearly summarizes the main fix: adding support for deserialization of PostgreSQL integer array types (INT2/INT4/INT8 arrays), including the issue reference.
Linked Issues check ✅ Passed PR fully addresses issue #27: implements explicit decoding for INT2[], INT4[], INT8[] array types in the patched deserializer with proper NULL-element preservation and JSON numeric output, directly resolving the 'unsupported datatype' error.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving issue #27: the deserializer fix, test script, documentation updates, and changelog entry are all necessary and on-topic.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/27-int-array-deserializer

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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
@openidle-dev openidle-dev force-pushed the fix/27-int-array-deserializer branch from d18fdf1 to e39e0d9 Compare May 14, 2026 07:13
@openidle-dev openidle-dev merged commit e8a009f into main May 14, 2026
10 checks passed
@openidle-dev openidle-dev deleted the fix/27-int-array-deserializer branch May 14, 2026 07:23
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.

Result deserializer errors on INT4[] / int[] columns: 'unsupported datatype'

2 participants