channel_message.rs

 1use crate::db::{ChannelId, MessageId, UserId};
 2use sea_orm::entity::prelude::*;
 3use time::PrimitiveDateTime;
 4
 5#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
 6#[sea_orm(table_name = "channel_messages")]
 7pub struct Model {
 8    #[sea_orm(primary_key)]
 9    pub id: MessageId,
10    pub channel_id: ChannelId,
11    pub sender_id: UserId,
12    pub body: String,
13    pub sent_at: PrimitiveDateTime,
14    pub nonce: Uuid,
15    pub reply_to_message_id: Option<MessageId>,
16}
17
18impl ActiveModelBehavior for ActiveModel {}
19
20#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
21pub enum Relation {
22    #[sea_orm(
23        belongs_to = "super::channel::Entity",
24        from = "Column::ChannelId",
25        to = "super::channel::Column::Id"
26    )]
27    Channel,
28    #[sea_orm(
29        belongs_to = "super::user::Entity",
30        from = "Column::SenderId",
31        to = "super::user::Column::Id"
32    )]
33    Sender,
34}
35
36impl Related<super::channel::Entity> for Entity {
37    fn to() -> RelationDef {
38        Relation::Channel.def()
39    }
40}
41
42impl Related<super::user::Entity> for Entity {
43    fn to() -> RelationDef {
44        Relation::Sender.def()
45    }
46}