cratestack_sqlx/partial_row.rs
1//! Partial-row decoder trait — see [`crate::FindMany::select`] for
2//! the typed-builder side of the column-projection feature.
3
4use crate::sqlx;
5
6/// Companion to [`sqlx::FromRow`] that decodes a row projected by
7/// `.select(...)` — i.e. a row where only the named columns are
8/// present in the SQL `SELECT` list. Non-selected fields populate to
9/// their type's `Default::default()` value.
10///
11/// The macro emits this impl for every generated model struct, so the
12/// trait is invisible to schema authors at the call site; it shows up
13/// as the bound on the typed builder's `T` generic.
14pub trait FromPartialPgRow: Sized {
15 /// Decode `row` into `Self` using `selected` as the projection
16 /// manifest. `selected` carries the SQL column names
17 /// (snake_case) the caller asked for; any column not in this
18 /// list falls through to `Default::default()`.
19 fn decode_partial_pg_row(
20 row: &sqlx::postgres::PgRow,
21 selected: &[&str],
22 ) -> Result<Self, sqlx::Error>;
23}