Skip to main content

systemprompt_agent/repository/context/
mod.rs

1pub mod message;
2mod mutations;
3mod queries;
4
5use crate::repository::Repository;
6use sqlx::PgPool;
7use std::sync::Arc;
8use systemprompt_database::DbPool;
9use systemprompt_traits::RepositoryError;
10
11#[derive(Debug, Clone)]
12pub struct ContextRepository {
13    db_pool: DbPool,
14}
15
16impl ContextRepository {
17    #[must_use]
18    pub const fn new(db_pool: DbPool) -> Self {
19        Self { db_pool }
20    }
21
22    fn get_pg_pool(&self) -> Result<Arc<PgPool>, RepositoryError> {
23        self.db_pool.as_ref().get_postgres_pool().ok_or_else(|| {
24            RepositoryError::InvalidData("PostgreSQL pool not available".to_string())
25        })
26    }
27}
28
29impl Repository for ContextRepository {
30    fn pool(&self) -> &DbPool {
31        &self.db_pool
32    }
33}
34
35impl systemprompt_traits::Repository for ContextRepository {
36    type Pool = DbPool;
37    type Error = RepositoryError;
38
39    fn pool(&self) -> &Self::Pool {
40        &self.db_pool
41    }
42}