mayhem_db/models/server/
member.rs1use 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 name: String,
11 pub nick: String,
12 pub server_id: i32,
13}
14
15#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn, Serialize, Deserialize)]
16pub enum Column {
17 Id,
18 Name,
19 Nick,
20 ServerId,
21}
22
23#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey, Serialize, Deserialize)]
24pub enum PrimaryKey {
25 Id,
26}
27
28#[derive(Copy, Clone, Debug, EnumIter, Serialize, Deserialize)]
29pub enum Relation {
30 Roles,
31 Server,
32}
33
34impl EntityName for Entity {
35 fn table_name(&self) -> &str {
36 return "server_members";
37 }
38}
39
40impl ColumnTrait for Column {
41 type EntityName = Entity;
42
43 fn def(&self) -> ColumnDef {
44 match self {
45 Self::Id => ColumnType::Integer.def(),
46 Self::Name => ColumnType::Text.def(),
47 Self::Nick => ColumnType::Text.def(),
48 Self::ServerId => ColumnType::Integer.def(),
49 }
50 }
51}
52
53impl PrimaryKeyTrait for PrimaryKey {
54 type ValueType = i32;
55
56 fn auto_increment() -> bool {
57 return true;
58 }
59}
60
61impl Related<super::role::Entity> for Entity {
62 fn to() -> RelationDef {
63 return super::member_role::Relation::Role.def();
64 }
65
66 fn via() -> Option<RelationDef> {
67 return Some(super::member_role::Relation::Member.def().rev());
68 }
69}
70
71impl Related<super::server::Entity> for Entity {
72 fn to() -> RelationDef {
73 return Relation::Server.def();
74 }
75}
76
77impl RelationTrait for Relation {
78 fn def(&self) -> RelationDef {
79 match self {
80 Self::Roles => Entity::has_many(super::role::Entity).into(),
81
82 Self::Server => Entity::belongs_to(super::server::Entity)
83 .from(Column::ServerId)
84 .to(super::server::Column::Id)
85 .into(),
86 }
87 }
88}
89
90impl ActiveModelBehavior for ActiveModel {}