use nodedb_sql::types::CollectionInfo;
use crate::control::security::identity::AuthenticatedIdentity;
use crate::control::state::SharedState;
use super::schema::{catalog_collection_info, known_table};
use super::{audit_log, dropped_collections, l2_cleanup_queue, tables};
pub async fn catalog_rows(
name: &str,
state: &SharedState,
identity: &AuthenticatedIdentity,
) -> crate::Result<Vec<Vec<u8>>> {
match known_table(name) {
Some("pg_database") => tables::pg_database(),
Some("pg_namespace") => tables::pg_namespace(),
Some("pg_type") => tables::pg_type(),
Some("pg_class") => tables::pg_class(state, identity),
Some("pg_attribute") => tables::pg_attribute(state, identity),
Some("pg_attrdef") => tables::pg_attrdef(state, identity),
Some("pg_collation") => tables::pg_collation(),
Some("pg_index") => tables::pg_index(state, identity),
Some("pg_range") => tables::pg_range(),
Some("pg_authid") => tables::pg_authid(state, identity),
Some("_system.audit_log") => audit_log::audit_log(state, identity),
Some("_system.dropped_collections") => {
dropped_collections::dropped_collections(state, identity).await
}
Some("_system.l2_cleanup_queue") => l2_cleanup_queue::l2_cleanup_queue(state, identity),
_ => Ok(Vec::new()),
}
}
pub struct CatalogProvider;
impl CatalogProvider {
pub fn schema(&self, name: &str) -> Option<CollectionInfo> {
catalog_collection_info(name)
}
pub async fn rows(
&self,
name: &str,
state: &SharedState,
identity: &AuthenticatedIdentity,
) -> crate::Result<Vec<Vec<u8>>> {
catalog_rows(name, state, identity).await
}
}