Skip to main content

sway_groups_core/db/entities/
output.rs

1//! Output entity for sway-groups.
2
3use sea_orm::entity::prelude::*;
4
5/// Output model representing a sway output/monitor.
6#[sea_orm::model]
7#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
8#[sea_orm(table_name = "outputs")]
9pub struct Model {
10    #[sea_orm(primary_key, auto_increment = true)]
11    pub id: i32,
12
13    #[sea_orm(unique)]
14    pub name: String,
15
16    #[sea_orm(nullable)]
17    pub active_group: Option<String>,
18
19    #[sea_orm(nullable)]
20    pub created_at: Option<DateTime>,
21
22    #[sea_orm(nullable)]
23    pub updated_at: Option<DateTime>,
24}
25
26/// Active model for output.
27impl ActiveModelBehavior for ActiveModel {}
28
29impl Entity {
30    pub fn find_by_active_group(active_group: &Option<String>) -> Select<Self> {
31        use sea_orm::{ColumnTrait, QueryFilter};
32        match active_group {
33            Some(group) => Self::find()
34                .filter(Column::ActiveGroup.eq(group.clone())),
35            None => Self::find()
36                .filter(Column::ActiveGroup.is_null()),
37        }
38    }
39
40    pub fn find_all_ordered() -> Select<Self> {
41        use sea_orm::QueryOrder;
42        Self::find().order_by_asc(Column::Name)
43    }
44}