1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
mod active_model;
mod from_query_result;
mod plain;

#[cfg(test)]
mod test;

pub use {
    active_model::{ActiveModel, ActiveValue, HasActiveModel, NamedValue, UpdateModel},
    from_query_result::{FromQueryResult, FromQueryResultMapping},
};

pub trait ModelData: std::fmt::Debug + Sized {
    const TABLE: &'static str;
    const TABLE_WITH_POINT: &'static str;
}

pub trait Model: ModelData + HasActiveModel {
    const PRIMARY: &'static str;

    type Primary;

    fn primary(&self) -> crate::types::Value;

    fn active_model() -> <Self as HasActiveModel>::ActiveModel {
        <Self as HasActiveModel>::ActiveModel::default()
    }

    fn update_model(&self) -> UpdateModel<Self> {
        UpdateModel::new(self.primary())
    }
}