Skip to main content

sway_groups_core/db/entities/
group.rs

1//! Group entity for sway-groups.
2
3use sea_orm::entity::prelude::*;
4use sea_orm::{DbErr, EntityTrait};
5
6/// Group model representing a named collection of workspaces.
7#[sea_orm::model]
8#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
9#[sea_orm(table_name = "groups")]
10pub struct Model {
11    #[sea_orm(primary_key, auto_increment = true)]
12    pub id: i32,
13
14    #[sea_orm(unique)]
15    pub name: String,
16
17    #[sea_orm(nullable)]
18    pub created_at: Option<DateTime>,
19
20    #[sea_orm(nullable)]
21    pub updated_at: Option<DateTime>,
22
23    #[sea_orm(nullable)]
24    pub last_visited: Option<DateTime>,
25
26    #[sea_orm(nullable)]
27    pub last_active_output: Option<String>,
28}
29
30/// Active model for group.
31impl ActiveModelBehavior for ActiveModel {}
32
33/// Extension methods for group queries.
34impl Entity {
35    /// Find all groups ordered by name.
36    pub fn find_all_ordered() -> Select<Self> {
37        use sea_orm::QueryOrder;
38        Self::find().order_by_asc(Column::Name)
39    }
40}