Skip to main content

systemprompt_database/repository/
info.rs

1use crate::models::{DatabaseInfo, TableInfo};
2use crate::services::Database;
3use anyhow::Result;
4use std::sync::Arc;
5
6#[derive(Debug)]
7pub struct DatabaseInfoRepository {
8    db: Arc<Database>,
9}
10
11impl DatabaseInfoRepository {
12    #[must_use]
13    pub const fn new(db: Arc<Database>) -> Self {
14        Self { db }
15    }
16
17    pub async fn get_database_info(&self) -> Result<DatabaseInfo> {
18        self.db.get_info().await
19    }
20
21    pub async fn list_tables(&self) -> Result<Vec<TableInfo>> {
22        let info = self.db.get_info().await?;
23        Ok(info.tables)
24    }
25
26    pub async fn get_table_info(&self, table_name: &str) -> Result<Option<TableInfo>> {
27        let info = self.db.get_info().await?;
28        Ok(info.tables.into_iter().find(|t| t.name == table_name))
29    }
30}