channel.rs

 1use crate::db::{ChannelId, ChannelVisibility};
 2use sea_orm::entity::prelude::*;
 3
 4#[derive(Clone, Debug, Default, PartialEq, Eq, DeriveEntityModel)]
 5#[sea_orm(table_name = "channels")]
 6pub struct Model {
 7    #[sea_orm(primary_key)]
 8    pub id: ChannelId,
 9    pub name: String,
10    pub visibility: ChannelVisibility,
11}
12
13impl ActiveModelBehavior for ActiveModel {}
14
15#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
16pub enum Relation {
17    #[sea_orm(has_one = "super::room::Entity")]
18    Room,
19    #[sea_orm(has_one = "super::buffer::Entity")]
20    Buffer,
21    #[sea_orm(has_many = "super::channel_member::Entity")]
22    Member,
23    #[sea_orm(has_many = "super::channel_buffer_collaborator::Entity")]
24    BufferCollaborators,
25    #[sea_orm(has_many = "super::channel_chat_participant::Entity")]
26    ChatParticipants,
27}
28
29impl Related<super::channel_member::Entity> for Entity {
30    fn to() -> RelationDef {
31        Relation::Member.def()
32    }
33}
34
35impl Related<super::room::Entity> for Entity {
36    fn to() -> RelationDef {
37        Relation::Room.def()
38    }
39}
40
41impl Related<super::buffer::Entity> for Entity {
42    fn to() -> RelationDef {
43        Relation::Buffer.def()
44    }
45}
46
47impl Related<super::channel_buffer_collaborator::Entity> for Entity {
48    fn to() -> RelationDef {
49        Relation::BufferCollaborators.def()
50    }
51}
52
53impl Related<super::channel_chat_participant::Entity> for Entity {
54    fn to() -> RelationDef {
55        Relation::ChatParticipants.def()
56    }
57}