Skip to main content

sway_groups_core/db/entities/
workspace.rs

1//! Workspace entity for sway-groups.
2
3use sea_orm::entity::prelude::*;
4
5/// Workspace model representing a sway workspace.
6#[sea_orm::model]
7#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
8#[sea_orm(table_name = "workspaces")]
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 number: Option<i32>,
18
19    #[sea_orm(nullable)]
20    pub output: Option<String>,
21
22    #[sea_orm(default = false)]
23    pub is_global: bool,
24
25    #[sea_orm(nullable)]
26    pub created_at: Option<DateTime>,
27
28    #[sea_orm(nullable)]
29    pub updated_at: Option<DateTime>,
30}
31
32/// Active model for workspace.
33impl ActiveModelBehavior for ActiveModel {}
34
35/// Extension methods for workspace queries.
36impl Entity {
37    /// Find workspace by number.
38    pub fn find_by_number(number: i32) -> Select<Self> {
39        Self::find().filter(Column::Number.eq(number))
40    }
41
42    /// Find all workspaces on an output.
43    pub fn find_by_output(output: &str) -> Select<Self> {
44        Self::find().filter(Column::Output.eq(output))
45    }
46
47    /// Find all global workspaces.
48    pub fn find_global() -> Select<Self> {
49        Self::find().filter(Column::IsGlobal.eq(true))
50    }
51}