Skip to main content

Module parametric

Module parametric 

Source
Expand description

Parametric type validators — Phase 4 partial drop.

The full Fase 3 plan calls for DataType::Varchar { max_len } and DataType::Decimal { precision, scale } baked into the DataType enum. That migration cascades into hundreds of pattern-match sites and requires cargo verification to land safely. Until that session runs, this module ships the validators as standalone functions so the rest of the codebase can use them today via coerce::coerce_via_catalog without touching DataType.

Once the enum migration lands, these functions become the body of the cast-catalog entries for the parametric variants.

§Coverage

  • validate_varchar(s, max_len) — Postgres-strict (rejects strings longer than max_len). Configurable via VarcharMode::Truncate for SQL Server-style behavior.
  • validate_decimal(value, precision, scale) — verifies the value fits in precision total digits with scale digits after the decimal point.
  • parse_varchar_modifier, parse_decimal_modifier — pull (n) / (p, s) out of the legacy SqlTypeName modifiers so callers don’t reinvent the parsing.

Enums§

ParametricError
Errors raised by the parametric validators.
VarcharMode
VARCHAR length-check policy. Postgres rejects; SQL Server silently truncates. reddb defaults to Postgres-strict.

Functions§

parse_decimal_modifier
Pull (p, s) out of DECIMAL(p, s)’s SqlTypeName modifiers. Returns (precision, scale) on success.
parse_varchar_modifier
Pull (n) out of VARCHAR(n)’s SqlTypeName modifiers. Returns Err if the modifier list is empty, has more than one element, or the single element isn’t a Number.
validate_decimal
Validate a Value::Decimal against declared (precision, scale). precision is the maximum total digit count (both sides of the decimal point); scale is the maximum fractional digit count.
validate_varchar
Validate a Value::Text against a declared VARCHAR length limit. Returns the value unchanged on success, or a coerced truncated copy when mode == Truncate.