use crate::entities::buffer;
use crate::entities::human;
use crate::entities::llm;
use crate::entities::model_deployment;
use crate::entities::training_job;
use sea_orm::*;
pub struct Mutation;
impl Mutation {
pub async fn create_buffer(
db: &DatabaseConnection,
form_data: buffer::ActiveModel,
) -> Result<buffer::Model, DbErr> {
form_data.insert(db).await
}
pub async fn delete_buffer(db: &DatabaseConnection, id: &str) -> Result<DeleteResult, DbErr> {
buffer::Entity::delete_by_id(id).exec(db).await
}
pub async fn update_buffer(
db: &DatabaseConnection,
form_data: &buffer::ActiveModel,
) -> Result<buffer::Model, DbErr> {
form_data.clone().update(db).await
}
pub async fn create_deployment(
db: &DatabaseConnection,
form_data: model_deployment::ActiveModel,
) -> Result<model_deployment::Model, DbErr> {
form_data.insert(db).await
}
pub async fn delete_deployment(
db: &DatabaseConnection,
id: &str,
) -> Result<DeleteResult, DbErr> {
model_deployment::Entity::delete_by_id(id).exec(db).await
}
pub async fn update_deployment_status(
db: &DatabaseConnection,
id: &str,
status: String,
) -> Result<model_deployment::Model, DbErr> {
let mut deployment: model_deployment::ActiveModel =
model_deployment::Entity::find_by_id(id)
.one(db)
.await?
.ok_or(DbErr::Custom("Deployment not found".to_string()))?
.into();
deployment.status = Set(Some(status));
deployment.updated_at = Set(chrono::Utc::now().into());
deployment.update(db).await
}
pub async fn update_training_job_status(
db: &DatabaseConnection,
id: &str,
new_status: &str,
) -> Result<training_job::Model, DbErr> {
let Some(job) = training_job::Entity::find_by_id(id).one(db).await? else {
return Err(DbErr::Custom(format!("Training job not found: {}", id)));
};
let mut active_model: training_job::ActiveModel = job.into();
active_model.status = Set(Some(new_status.to_string()));
active_model.updated_at = Set(chrono::Utc::now().into());
active_model.update(db).await
}
pub async fn create_training_job(
db: &DatabaseConnection,
form_data: training_job::ActiveModel,
) -> Result<training_job::Model, DbErr> {
form_data.insert(db).await
}
pub async fn delete_llm_by_name_namespace_and_owners(
db: &DatabaseConnection,
name: &str,
namespace: &str,
owner_ids: &[&str],
) -> Result<u64, DbErr> {
let delete_result = llm::Entity::delete_many()
.filter(llm::Column::Name.eq(name))
.filter(llm::Column::Namespace.eq(namespace))
.filter(llm::Column::OwnerId.is_in(owner_ids.iter().copied()))
.exec(db)
.await?;
Ok(delete_result.rows_affected)
}
pub async fn delete_human_by_name_namespace_and_owners(
db: &DatabaseConnection,
name: &str,
namespace: &str,
owner_ids: &[&str],
) -> Result<u64, DbErr> {
Ok(human::Entity::delete_many()
.filter(human::Column::Name.eq(name))
.filter(human::Column::Namespace.eq(namespace))
.filter(human::Column::OwnerId.is_in(owner_ids.iter().copied()))
.exec(db)
.await?
.rows_affected)
}
pub async fn update_llm(
db: &DatabaseConnection,
form_data: &llm::ActiveModel,
) -> Result<llm::Model, DbErr> {
form_data.clone().update(db).await
}
}