backbone-mail 0.2.32

Odoo mail core port — message/notification/followers/activity/alias/sms queue (schema: messaging)
//! Repository for DiscussChannel entities
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! Thin newtype over `backbone_orm::GenericCrudRepository<DiscussChannel, backbone_orm::SoftDelete>`.
//! All standard CRUD methods are available via `Deref`.

use anyhow::Result;
use sqlx::PgPool;

use crate::domain::entity::DiscussChannel;

/// Table name for DiscussChannel entities
pub const TABLE_NAME: &str = "messaging.discuss_channels";

/// Repository for DiscussChannel entities.
///
/// All standard CRUD, soft-delete, pagination, and bulk methods are
/// provided automatically via `Deref` to `backbone_orm::GenericCrudRepository`.
pub struct DiscussChannelRepository(
    backbone_orm::GenericCrudRepository<DiscussChannel, backbone_orm::SoftDelete>,
);

impl std::ops::Deref for DiscussChannelRepository {
    type Target = backbone_orm::GenericCrudRepository<DiscussChannel, backbone_orm::SoftDelete>;
    fn deref(&self) -> &Self::Target { &self.0 }
}

impl DiscussChannelRepository {
    /// Create a new repository instance.
    pub fn new(pool: PgPool) -> Self {
        Self(backbone_orm::GenericCrudRepository::new(pool, TABLE_NAME))
    }
}

impl DiscussChannelRepository {
    /// Find discuss_channel by uuid (excludes soft-deleted)
    pub async fn find_by_uuid(&self, uuid: Option<String>) -> Result<Option<DiscussChannel>> {
        let query = format!("SELECT * FROM {} WHERE uuid = $1 AND metadata->>'deleted_at' IS NULL", self.table_name());
        let result = sqlx::query_as::<_, DiscussChannel>(&query)
            .bind(uuid)
            .fetch_optional(self.pool())
            .await?;
        Ok(result)
    }

    /// Check if discuss_channel exists by uuid (excludes soft-deleted)
    pub async fn exists_by_uuid(&self, uuid: Option<String>) -> Result<bool> {
        let query = format!("SELECT 1 FROM {} WHERE uuid = $1 AND metadata->>'deleted_at' IS NULL LIMIT 1", self.table_name());
        let result = sqlx::query_scalar::<_, i32>(&query)
            .bind(uuid)
            .fetch_optional(self.pool())
            .await?;
        Ok(result.is_some())
    }

}

backbone_core::impl_crud_repository!(DiscussChannelRepository, DiscussChannel, soft_delete);