mayhem_db/models/server/
channel.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 server_id: i32,
12 pub channel_type: String,
13}
14
15#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn, Serialize, Deserialize)]
16pub enum Column {
17 Id,
18 Name,
19 ServerId,
20 ChannelType,
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 Server,
31 Message,
32}
33
34impl EntityName for Entity {
35 fn table_name(&self) -> &str {
36 return "server_channels";
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::ServerId => ColumnType::Integer.def(),
48 Self::ChannelType => ColumnType::Text.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::server::Entity> for Entity {
62 fn to() -> RelationDef {
63 return Relation::Server.def();
64 }
65}
66
67impl Related<super::super::message::Entity> for Entity {
68 fn to() -> RelationDef {
69 return Relation::Message.def();
70 }
71}
72
73impl RelationTrait for Relation {
74 fn def(&self) -> RelationDef {
75 match self {
76 Self::Server => Entity::belongs_to(super::server::Entity)
77 .from(Column::ServerId)
78 .to(super::server::Column::Id)
79 .into(),
80
81 Self::Message => Entity::has_many(super::super::message::Entity).into(),
82 }
83 }
84}
85
86impl ActiveModelBehavior for ActiveModel {}