mithril_persistence/sqlite/
entity.rs

1use sqlite::Row;
2use thiserror::Error;
3
4use super::Projection;
5
6/// SqLite hydration error
7#[derive(Error, Debug)]
8pub enum HydrationError {
9    /// data do not conform to expectations
10    #[error("data do not conform to expectations: {0}")]
11    InvalidData(String),
12}
13
14/// How to hydrate an entity from a SQLite result row
15pub trait SqLiteEntity {
16    /// This method is intended to be used when creating new instances from SQL
17    /// result rows. This is the place to grab data, check consistency and types
18    /// and return the entity if possible.
19    fn hydrate(row: Row) -> Result<Self, HydrationError>
20    where
21        Self: Sized;
22
23    /// Construct a [Projection] that will allow to hydrate this `SqLiteEntity`.
24    fn get_projection() -> Projection;
25}