Skip to main content

systemprompt_runtime/
database_context.rs

1use anyhow::Result;
2use std::sync::Arc;
3use systemprompt_database::{Database, DbPool};
4
5#[derive(Debug, Clone)]
6pub struct DatabaseContext {
7    database: DbPool,
8}
9
10impl DatabaseContext {
11    pub async fn from_url(database_url: &str) -> Result<Self> {
12        let db = Database::new_postgres(database_url).await?;
13        Ok(Self {
14            database: Arc::new(db),
15        })
16    }
17
18    pub const fn db_pool(&self) -> &DbPool {
19        &self.database
20    }
21
22    pub fn db_pool_arc(&self) -> DbPool {
23        Arc::clone(&self.database)
24    }
25}