turso_orm/entity/partial_model.rs
1//! Partial models, modeled by [`PartialModelTrait`].
2//!
3//! A partial model is a struct that reads a subset of an entity's columns,
4//! or expressions computed from them, instead of the whole row. Where a
5//! plain `FromQueryResult` struct only knows how to decode a row, a partial
6//! model also knows which select list produces that row, so that
7//! `Select::into_partial_model` can build the projection and the decoder
8//! from one declaration. `DerivePartialModel` implements both traits from
9//! the field list and its `#[turso(...)]` attributes.
10
11use super::model::FromQueryResult;
12
13/// A projection struct that selects its own columns.
14pub trait PartialModelTrait: FromQueryResult {
15 /// Adds to `select`, whose select list has been cleared, one aliased
16 /// item per field, named after the field so that decoding finds it.
17 fn select_cols(select: turso_sql::Select) -> turso_sql::Select;
18}