buffer.rs

 1use crate::db::{BufferId, ChannelId};
 2use sea_orm::entity::prelude::*;
 3
 4#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
 5#[sea_orm(table_name = "buffers")]
 6pub struct Model {
 7    #[sea_orm(primary_key)]
 8    pub id: BufferId,
 9    pub epoch: i32,
10    pub channel_id: ChannelId,
11}
12
13#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
14pub enum Relation {
15    #[sea_orm(has_many = "super::buffer_operation::Entity")]
16    Operations,
17    #[sea_orm(has_many = "super::buffer_snapshot::Entity")]
18    Snapshots,
19    #[sea_orm(
20        belongs_to = "super::channel::Entity",
21        from = "Column::ChannelId",
22        to = "super::channel::Column::Id"
23    )]
24    Channel,
25    #[sea_orm(has_many = "super::channel_buffer_collaborator::Entity")]
26    Collaborators,
27}
28
29impl Related<super::buffer_operation::Entity> for Entity {
30    fn to() -> RelationDef {
31        Relation::Operations.def()
32    }
33}
34
35impl Related<super::buffer_snapshot::Entity> for Entity {
36    fn to() -> RelationDef {
37        Relation::Snapshots.def()
38    }
39}
40
41impl Related<super::channel::Entity> for Entity {
42    fn to() -> RelationDef {
43        Relation::Channel.def()
44    }
45}
46
47impl Related<super::channel_buffer_collaborator::Entity> for Entity {
48    fn to() -> RelationDef {
49        Relation::Collaborators.def()
50    }
51}
52
53impl ActiveModelBehavior for ActiveModel {}