systemprompt_database/repository/
info.rs1use crate::models::{DatabaseInfo, TableInfo};
2use crate::services::Database;
3use anyhow::Result;
4use std::sync::Arc;
5use systemprompt_traits::{Repository as RepositoryTrait, RepositoryError};
6
7#[derive(Debug)]
8pub struct DatabaseInfoRepository {
9 db: Arc<Database>,
10}
11
12impl RepositoryTrait for DatabaseInfoRepository {
13 type Pool = Arc<Database>;
14 type Error = RepositoryError;
15
16 fn pool(&self) -> &Self::Pool {
17 &self.db
18 }
19}
20
21impl DatabaseInfoRepository {
22 #[must_use]
23 pub const fn new(db: Arc<Database>) -> Self {
24 Self { db }
25 }
26
27 pub async fn get_database_info(&self) -> Result<DatabaseInfo> {
28 self.db.get_info().await
29 }
30
31 pub async fn list_tables(&self) -> Result<Vec<TableInfo>> {
32 let info = self.db.get_info().await?;
33 Ok(info.tables)
34 }
35
36 pub async fn get_table_info(&self, table_name: &str) -> Result<Option<TableInfo>> {
37 let info = self.db.get_info().await?;
38 Ok(info.tables.into_iter().find(|t| t.name == table_name))
39 }
40}