1
0
Fork 0
forked from 2sys/shoutdotdev
shoutdotdev/src/channel_selections.rs

37 lines
963 B
Rust
Raw Normal View History

2025-02-26 13:10:45 -08:00
use diesel::{
dsl::{auto_type, AsSelect},
pg::Pg,
prelude::*,
};
use uuid::Uuid;
use crate::schema::channel_selections;
#[derive(Associations, Clone, Debug, Identifiable, Queryable, Selectable)]
#[diesel(belongs_to(crate::channels::Channel))]
#[diesel(belongs_to(crate::projects::Project))]
#[diesel(primary_key(channel_id, project_id))]
#[diesel(check_for_backend(Pg))]
pub struct ChannelSelection {
pub project_id: Uuid,
pub channel_id: Uuid,
}
impl ChannelSelection {
#[auto_type(no_type_alias)]
pub fn all() -> _ {
let select: AsSelect<ChannelSelection, Pg> = Self::as_select();
channel_selections::table.select(select)
}
#[auto_type(no_type_alias)]
pub fn with_channel(channel_id: Uuid) -> _ {
channel_selections::channel_id.eq(channel_id)
}
#[auto_type(no_type_alias)]
pub fn with_project(project_id: Uuid) -> _ {
channel_selections::project_id.eq(project_id)
}
}