Skip to content

ToSqlParam coverage: Numeric, Interval, Geography, JSON #65

@StefanSteiner

Description

@StefanSteiner

Summary

ToSqlParam is implemented for primitives, Date/Time/Timestamp/OffsetTimestamp, byte slices, and strings, but not for Numeric, Interval, Geography, or JSON. Users who want to bind these types as query parameters must stringify them by hand — even though the types themselves already round-trip through IntoValue/RowValue and SqlType::Json is a recognized SQL type.

Current state

hyperdb-api/src/params.rs lists every implementing type starting at line 27. Confirmed missing impls:

$ grep -nE "impl ToSqlParam (for|<.+> for) (Numeric|Interval|Geography|serde_json|Json)" hyperdb-api/src/params.rs
# (no output)

Existing impls per params.rs:114-416:

  • Numeric: i16, i32, i64, f32, f64, bool
  • Strings/bytes: str, String, &str, [u8], Vec<u8>
  • Time: Date, Time, Timestamp, OffsetTimestamp
  • Generic: &T, Option<T>

Original gap analysis: §5 of docs/RUST_API_GAP_ANALYSIS.md (predecessor repo) — "Interval — exists in IntoValue/RowValue but not ToSqlParam. Numeric — same. Geography — neither ToSqlParam nor IntoValue. serde_json::Value / native JSON type — SqlType::Json exists, but no first-class reader/writer."

Proposed work

  • impl ToSqlParam for Numeric — fixed-precision decimals.
  • impl ToSqlParam for Interval.
  • impl ToSqlParam for Geography (and add IntoValue if missing — the gap analysis flagged that gap too).
  • First-class JSON support:
    • impl ToSqlParam for serde_json::Value (behind a serde-json feature flag, off by default to avoid pulling serde_json into builds that don't need it).
    • Companion reader path on Row::get so users can round-trip serde_json::Value instead of stringifying.
    • Document the feature flag and example in hyperdb-api/examples/.
  • Tests verifying each new impl round-trips through query_params and the inserter path.

Backwards compatibility

Purely additive. New trait impls + one new (default-off) feature flag for the serde_json integration.

Open questions

  • For Numeric: bind via the binary encoding path (encode_param) or text (to_sql_literal)? Binary is faster but query_params currently routes everything through text per params.rs:82. Worth deciding in scope of this issue.
  • For Geography: which Rust geo type is canonical — geo_types::Geometry (already a dependency per DEVELOPMENT.md) or a hyperdb_api-owned newtype?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions