Skip to content

fix: MONEY columns always read as null - #41

Merged
aesslinger merged 1 commit into
mainfrom
fix/money-type-extraction
Aug 19, 2026
Merged

fix: MONEY columns always read as null#41
aesslinger merged 1 commit into
mainfrom
fix/money-type-extraction

Conversation

@aesslinger

Copy link
Copy Markdown
Collaborator

Summary

extract_value (src/extract.rs) had no case for Type::MONEY, so it fell through to the generic fallback branch (row.try_get::<_, String>(index)). But String's FromSql::accepts returns false for Type::MONEY — confirmed directly: <String as FromSql>::accepts(&Type::MONEY) == false. So that fallback failed every single time regardless of the actual column value, and every MONEY column read back as JSON null.

MONEY is listed as a supported numeric type in the README's "Supported PostgreSQL Data Types" table and used in ddl.rs's implicit-cast-compatible type group — so this was a real, user-visible correctness bug hiding behind advertised support.

Fixes #39.

Fix

Added a Money wrapper mirroring the builtin driver's extract/advanced_types.rs::Money. MONEY is wire-encoded identically to INT8 (an 8-byte big-endian i64, in the smallest fractional unit — e.g. cents), so decoding just reinterprets those bytes via <i64 as FromSql>::from_sql(&Type::INT8, raw) and reuses this file's existing i64_to_json helper for the same JS-safe-integer stringification INT8 already gets.

Test plan

TDD: wrote money_accepts_only_the_money_type, money_decodes_the_same_8_byte_wire_format_as_int8, and money_above_js_safe_integer_becomes_a_string first (confirmed they failed to compile — Money didn't exist yet), then implemented until green.

  • cargo test --lib --bins — 91/91 pass (88 previous + 3 new)
  • cargo clippy --all-targets -- -D warnings — clean
  • cargo fmt --all -- --check — clean
  • npx markdownlint CHANGELOG.md — clean

@aesslinger aesslinger added the prerelease:beta Version suggestion targets a beta prerelease label Aug 19, 2026
@github-actions

Copy link
Copy Markdown

Version suggestion

Based on this PR's title (fix) and the prerelease:beta label:

Current 1.0.0-beta.7
Suggested next tag v1.0.0-beta.8

This is informational only — no tag or release is created automatically yet.

extract_value had no explicit case for Type::MONEY, so it fell
through to the generic fallback (try_get::<_, String>), but String's
FromSql::accepts returns false for Type::MONEY -- confirmed directly
via <String as FromSql>::accepts(&Type::MONEY) == false. So that
fallback failed every single time, regardless of the actual column
value, and every MONEY column came back as JSON null.

MONEY is listed as a supported numeric type in the README and used in
ddl.rs's implicit-cast-compatible group, so this was a real,
user-visible correctness bug hiding behind advertised support.

Added a Money wrapper mirroring the builtin driver's
extract/advanced_types.rs::Money: MONEY is wire-encoded identically to
INT8 (an 8-byte big-endian i64, in the smallest fractional unit), so
decoding just reinterprets those bytes and reuses the existing
i64_to_json helper for the same JS-safe-integer stringification INT8
already gets.

Fixes #39.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prerelease:beta Version suggestion targets a beta prerelease

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MONEY columns always read as null

1 participant