axion_db/introspection/
mod.rs1use crate::{
3 client::DbClient,
4 config::DatabaseType,
5 error::{DbError, DbResult},
6 metadata::{DatabaseMetadata, EnumMetadata, SchemaMetadata, TableMetadata, ViewMetadata},
7};
8use std::{collections::HashMap, sync::Arc};
9
10pub mod postgres;
12#[async_trait::async_trait]
16pub trait Introspector: Send + Sync {
17 async fn list_user_schemas(&self) -> DbResult<Vec<String>>;
18 async fn introspect(&self, schemas: &[String]) -> DbResult<DatabaseMetadata>;
19 async fn introspect_schema(&self, schema_name: &str) -> DbResult<SchemaMetadata>;
20 async fn introspect_table(
21 &self,
22 schema_name: &str,
23 table_name: &str,
24 ) -> DbResult<TableMetadata>;
25 async fn introspect_view(&self, schema_name: &str, view_name: &str) -> DbResult<ViewMetadata>;
26 async fn introspect_enums_for_schema(
27 &self,
28 schema_name: &str,
29 ) -> DbResult<HashMap<String, EnumMetadata>>;
30}
31
32pub fn new_introspector(client: Arc<DbClient>) -> DbResult<Box<dyn Introspector>> {
38 match client.config.db_type {
39 DatabaseType::Postgres => Ok(Box::new(postgres::PostgresIntrospector::new(client))),
40 _ => Err(DbError::UnsupportedDbType(
43 "This database type is not yet supported for introspection.".to_string(),
44 )),
45 }
46}