fix: MONEY columns always read as null - #41
Merged
Conversation
Version suggestionBased on this PR's title (
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.
aesslinger
force-pushed
the
fix/money-type-extraction
branch
from
August 19, 2026 13:59
88bd24a to
3d7cfc1
Compare
This was referenced Aug 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extract_value(src/extract.rs) had no case forType::MONEY, so it fell through to the generic fallback branch (row.try_get::<_, String>(index)). ButString'sFromSql::acceptsreturnsfalseforType::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 JSONnull.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
Moneywrapper mirroring the builtin driver'sextract/advanced_types.rs::Money. MONEY is wire-encoded identically toINT8(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 existingi64_to_jsonhelper for the same JS-safe-integer stringificationINT8already gets.Test plan
TDD: wrote
money_accepts_only_the_money_type,money_decodes_the_same_8_byte_wire_format_as_int8, andmoney_above_js_safe_integer_becomes_a_stringfirst (confirmed they failed to compile —Moneydidn't exist yet), then implemented until green.cargo test --lib --bins— 91/91 pass (88 previous + 3 new)cargo clippy --all-targets -- -D warnings— cleancargo fmt --all -- --check— cleannpx markdownlint CHANGELOG.md— clean