robson-core 0.1.0

Rust async agent orchestrator for automated development workflows
Documentation
use anyhow::Result;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

/// A registered communication gateway (e.g. "slack", "webhook").
///
/// Each `Conversation` row references a `Gateway` via `gateway_id`, which tells the
/// SensoriumLoop delivery loop which gateway to use when routing `ProcessEvent`s back
/// to the originating channel.
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "gateways")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i32,
    #[sea_orm(unique)]
    pub name: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}

impl Model {
    /// Look up a gateway by its unique name (e.g. `"slack"`, `"webhook"`).
    pub async fn find_by_name(db: &DatabaseConnection, name: &str) -> Result<Option<Model>> {
        Ok(Entity::find().filter(Column::Name.eq(name)).one(db).await?)
    }

    /// Look up a gateway by primary key.
    pub async fn find_by_id(db: &DatabaseConnection, id: i32) -> Result<Option<Model>> {
        Ok(Entity::find_by_id(id).one(db).await?)
    }

    /// Return all registered gateways.
    pub async fn find_all(db: &DatabaseConnection) -> Result<Vec<Model>> {
        Ok(Entity::find().all(db).await?)
    }
}