mayhem_db/models/
user_settings.rs

1use sea_orm::entity::prelude::*;
2use serde::{Deserialize, Serialize};
3
4#[derive(Copy, Clone, Default, Debug, DeriveEntity, Serialize, Deserialize)]
5pub struct Entity;
6
7#[derive(Clone, Debug, PartialEq, Eq, DeriveModel, DeriveActiveModel, Serialize, Deserialize)]
8pub struct Model {
9    pub id: i32,
10    pub user_id: i32,
11}
12
13#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn, Serialize, Deserialize)]
14pub enum Column {
15    Id,
16    UserId,
17}
18
19#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey, Serialize, Deserialize)]
20pub enum PrimaryKey {
21    Id,
22}
23
24#[derive(Copy, Clone, Debug, EnumIter, Serialize, Deserialize)]
25pub enum Relation {
26    User,
27}
28
29impl EntityName for Entity {
30    fn table_name(&self) -> &str {
31        return "user_settings";
32    }
33}
34
35impl ColumnTrait for Column {
36    type EntityName = Entity;
37
38    fn def(&self) -> ColumnDef {
39        match self {
40            Self::Id => ColumnType::Integer.def(),
41            Self::UserId => ColumnType::Integer.def(),
42        }
43    }
44}
45
46impl PrimaryKeyTrait for PrimaryKey {
47    type ValueType = i32;
48
49    fn auto_increment() -> bool {
50        return true;
51    }
52}
53
54impl Related<super::user::Entity> for Entity {
55    fn to() -> RelationDef {
56        return Relation::User.def();
57    }
58}
59
60impl RelationTrait for Relation {
61    fn def(&self) -> RelationDef {
62        match self {
63            Self::User => Entity::belongs_to(super::user::Entity)
64                .from(Column::UserId)
65                .to(super::user::Column::Id)
66                .into(),
67        }
68    }
69}
70
71impl ActiveModelBehavior for ActiveModel {}