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