Skip to main content

systemprompt_database/repository/
info.rs

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