use crate::{
client::DbClient,
config::DatabaseType,
error::{DbError, DbResult},
metadata::{DatabaseMetadata, EnumMetadata, SchemaMetadata, TableMetadata, ViewMetadata},
};
use std::{collections::HashMap, sync::Arc};
pub mod postgres;
#[async_trait::async_trait]
pub trait Introspector: Send + Sync {
async fn list_user_schemas(&self) -> DbResult<Vec<String>>;
async fn introspect(&self, schemas: &[String]) -> DbResult<DatabaseMetadata>;
async fn introspect_schema(&self, schema_name: &str) -> DbResult<SchemaMetadata>;
async fn introspect_table(
&self,
schema_name: &str,
table_name: &str,
) -> DbResult<TableMetadata>;
async fn introspect_view(&self, schema_name: &str, view_name: &str) -> DbResult<ViewMetadata>;
async fn introspect_enums_for_schema(
&self,
schema_name: &str,
) -> DbResult<HashMap<String, EnumMetadata>>;
}
pub fn new_introspector(client: Arc<DbClient>) -> DbResult<Box<dyn Introspector>> {
match client.config.db_type {
DatabaseType::Postgres => Ok(Box::new(postgres::PostgresIntrospector::new(client))),
_ => Err(DbError::UnsupportedDbType(
"This database type is not yet supported for introspection.".to_string(),
)),
}
}