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}
16
17impl ActiveModelBehavior for ActiveModel {}
18
19#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
20pub enum Relation {
21    #[sea_orm(
22        belongs_to = "super::channel::Entity",
23        from = "Column::ChannelId",
24        to = "super::channel::Column::Id"
25    )]
26    Channel,
27    #[sea_orm(
28        belongs_to = "super::user::Entity",
29        from = "Column::SenderId",
30        to = "super::user::Column::Id"
31    )]
32    Sender,
33}
34
35impl Related<super::channel::Entity> for Entity {
36    fn to() -> RelationDef {
37        Relation::Channel.def()
38    }
39}
40
41impl Related<super::user::Entity> for Entity {
42    fn to() -> RelationDef {
43        Relation::Sender.def()
44    }
45}