pub trait FromPgRow: Sized {
const COLUMNS: &'static [&'static str];
const COLUMN_LIST: &'static str;
// Required method
fn from_pg_row(row: &Row) -> Result<Self, DjogiError>;
}Expand description
Canonical row-decode trait for #[model]-annotated structs.
Do not implement this manually — #[model] emits the impl. Users
can still bound generic code on T: FromPgRow (e.g. to accept any
model in a helper function), which is the intended public shape.
§Contract
Implementors must guarantee that:
COLUMNSlists fields in the exact orderfrom_pg_rowreads them from the row (ordinal position matches slice index).COLUMN_LISTequalsCOLUMNS.join(", ")— callers interpolate it into SQL text expecting exactly that shape.from_pg_rowreturnsErr(DjogiError::Decode)on any column-level type-conversion failure, not panic. (The debug_assert on column-name drift is a separate invariant violation and is allowed to panic.)
Required Associated Constants§
Sourceconst COLUMNS: &'static [&'static str]
const COLUMNS: &'static [&'static str]
Column names in the canonical SELECT order (framework fields
first, then user fields).
COLUMNS[i] is the name of the column decoded by
from_pg_row at ordinal position i. The macro uses this
slice both to emit the per-column debug_assert_eq! name
guard and to build COLUMN_LIST at
compile time.
Sourceconst COLUMN_LIST: &'static str
const COLUMN_LIST: &'static str
Required Methods§
Sourcefn from_pg_row(row: &Row) -> Result<Self, DjogiError>
fn from_pg_row(row: &Row) -> Result<Self, DjogiError>
Decode Self from a tokio_postgres::Row positionally.
Column ordinals are fixed at macro time and match
COLUMNS index-for-index. Callers must
supply a row produced by a SELECT whose projection matches
COLUMN_LIST — the CRUD and QuerySet
terminals shipped by Djogi guarantee this; hand-rolled SELECTs
must either interpolate COLUMN_LIST or supply columns in the
same order.
Returns DjogiError::Decode with
the offending column name on wire-type mismatch.
In debug builds, a debug_assert_eq! on each
row.columns()[i].name() panics if the wire shape drifts
from COLUMNS. Release builds skip the
guard.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".