Skip to main content

Module row_ref

Module row_ref 

Source
Expand description

Bridge between tokio_postgres::Row and prax_query::row::RowRef.

RowRef is defined in prax-query and Row is defined in tokio-postgres; both are foreign to this crate, so Rust’s orphan rules forbid a direct impl RowRef for Row. We wrap the row in a #[repr(transparent)] newtype (PgRow) and implement the trait on the wrapper.

§Dual API surface

PgRow derefs to the wrapped Row, so callers can use either API:

  • The generic RowRef interface (pg_row.get_i32("id")) — portable across drivers and what generated FromRow impls use.
  • The native tokio_postgres::Row interface (pg_row.try_get::<_, i32>("id")) — full access to the driver’s type system for columns RowRef does not model (arrays, range types, etc.).

§rust_decimal limitation

tokio-postgres 0.7 has no with-rust_decimal-* feature gate and rust_decimal::Decimal therefore has no FromSql impl through the driver. PgRow::get_decimal and PgRow::get_decimal_opt fall back to the trait’s default implementations, which return a RowError::TypeConversion marked “decimal not supported by this row type”. Until we add a bridging FromSql/ToSql impl (or switch to a driver that exposes the feature), callers that need decimal values should cast the column to text (amount::text) and parse in application code.

Structs§

PgRow
Newtype wrapper around tokio_postgres::Row that implements prax_query::row::RowRef.