pub mod memory;
use async_trait::async_trait;
use fraiseql_error::Result;
use crate::types::RuntimeType;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum FunctionStatus {
Active,
Inactive,
}
impl FunctionStatus {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Active => "active",
Self::Inactive => "inactive",
}
}
#[must_use]
pub fn parse(s: &str) -> Option<Self> {
match s {
"active" => Some(Self::Active),
"inactive" => Some(Self::Inactive),
_ => None,
}
}
}
#[derive(Debug, Clone)]
pub struct FunctionRecord {
pub pk_function: i64,
pub name: String,
pub runtime: RuntimeType,
pub bytecode: bytes::Bytes,
pub version: i32,
pub deployed_at: chrono::DateTime<chrono::Utc>,
pub status: FunctionStatus,
}
#[async_trait]
pub trait FunctionStore: Send + Sync {
async fn store_function(
&self,
name: &str,
runtime: RuntimeType,
bytecode: bytes::Bytes,
) -> Result<FunctionRecord>;
async fn get_function(&self, name: &str) -> Result<Option<FunctionRecord>>;
async fn list_functions(&self) -> Result<Vec<FunctionRecord>>;
async fn delete_function(&self, name: &str) -> Result<bool>;
}