feat(xugu): expose table child metadata

This commit is contained in:
Elias authored and GitHub committed 2026-07-24 16:47:13 +08:00
1 parent 6ddfa8bd24
commit 0362fef273
33 files changed
+1269 -33

No files matched your search

@@ -52,6 +52,9 @@
"list_indexes",
"list_foreign_keys",
"list_triggers",
"list_constraints",
"list_partitions",
"list_subpartitions",
"execute_query",
"execute_query_page",
"fetch_query_page",
@@ -59,6 +59,9 @@
"list_indexes",
"list_foreign_keys",
"list_triggers",
"list_constraints",
"list_partitions",
"list_subpartitions",
"execute_query",
"execute_query_page",
"fetch_query_page",
+61 -1
View File
@@ -406,6 +406,9 @@ pub enum AgentMethod {
ListIndexes,
ListForeignKeys,
ListTriggers,
ListConstraints,
ListPartitions,
ListSubpartitions,
GetTableDdl,
ExecuteQuery,
ExecuteQueryPage,
@@ -422,7 +425,7 @@ pub enum AgentMethod {
}
impl AgentMethod {
pub const ALL: [Self; 33] = [
pub const ALL: [Self; 36] = [
Self::Handshake,
Self::Connect,
Self::OpenSession,
@@ -444,6 +447,9 @@ impl AgentMethod {
Self::ListIndexes,
Self::ListForeignKeys,
Self::ListTriggers,
Self::ListConstraints,
Self::ListPartitions,
Self::ListSubpartitions,
Self::ExecuteQuery,
Self::ExecuteQueryPage,
Self::FetchQueryPage,
@@ -481,6 +487,9 @@ impl AgentMethod {
Self::ListIndexes => "list_indexes",
Self::ListForeignKeys => "list_foreign_keys",
Self::ListTriggers => "list_triggers",
Self::ListConstraints => "list_constraints",
Self::ListPartitions => "list_partitions",
Self::ListSubpartitions => "list_subpartitions",
Self::ExecuteQuery => "execute_query",
Self::ExecuteQueryPage => "execute_query_page",
Self::FetchQueryPage => "fetch_query_page",
@@ -1192,6 +1201,51 @@ impl AgentDriverClient {
.await
}
pub async fn list_constraints<T: DeserializeOwned + Send + 'static>(
&mut self,
database: &str,
schema: &str,
table: &str,
timeout_duration: Option<Duration>,
) -> Result<T, String> {
self.call_method_with_timeout(
AgentMethod::ListConstraints,
agent_schema_table_params(database, schema, table),
timeout_duration,
)
.await
}
pub async fn list_partitions<T: DeserializeOwned + Send + 'static>(
&mut self,
database: &str,
schema: &str,
table: &str,
timeout_duration: Option<Duration>,
) -> Result<T, String> {
self.call_method_with_timeout(
AgentMethod::ListPartitions,
agent_schema_table_params(database, schema, table),
timeout_duration,
)
.await
}
pub async fn list_subpartitions<T: DeserializeOwned + Send + 'static>(
&mut self,
database: &str,
schema: &str,
table: &str,
timeout_duration: Option<Duration>,
) -> Result<T, String> {
self.call_method_with_timeout(
AgentMethod::ListSubpartitions,
agent_schema_table_params(database, schema, table),
timeout_duration,
)
.await
}
pub async fn get_table_ddl<T: DeserializeOwned + Send + 'static>(
&mut self,
database: &str,
@@ -2271,6 +2325,9 @@ for line in sys.stdin:
assert_eq!(AgentMethod::ListIndexes.as_str(), "list_indexes");
assert_eq!(AgentMethod::ListForeignKeys.as_str(), "list_foreign_keys");
assert_eq!(AgentMethod::ListTriggers.as_str(), "list_triggers");
assert_eq!(AgentMethod::ListConstraints.as_str(), "list_constraints");
assert_eq!(AgentMethod::ListPartitions.as_str(), "list_partitions");
assert_eq!(AgentMethod::ListSubpartitions.as_str(), "list_subpartitions");
assert_eq!(AgentMethod::GetTableDdl.as_str(), "get_table_ddl");
assert_eq!(AgentMethod::ExecuteQuery.as_str(), "execute_query");
assert_eq!(AgentMethod::ExecuteQueryPage.as_str(), "execute_query_page");
@@ -2323,6 +2380,9 @@ for line in sys.stdin:
let _list_indexes = AgentDriverClient::list_indexes::<serde_json::Value>;
let _list_foreign_keys = AgentDriverClient::list_foreign_keys::<serde_json::Value>;
let _list_triggers = AgentDriverClient::list_triggers::<serde_json::Value>;
let _list_constraints = AgentDriverClient::list_constraints::<serde_json::Value>;
let _list_partitions = AgentDriverClient::list_partitions::<serde_json::Value>;
let _list_subpartitions = AgentDriverClient::list_subpartitions::<serde_json::Value>;
let _get_table_ddl = AgentDriverClient::get_table_ddl::<serde_json::Value>;
let _execute_query = AgentDriverClient::execute_query::<serde_json::Value>;
let _execute_query_page = AgentDriverClient::execute_query_page::<serde_json::Value>;
+68
View File
@@ -5046,6 +5046,74 @@ pub async fn list_triggers_core(
.await
}
// These object kinds are currently exposed by the Xugu agent only. Keeping
// the core route generic makes the protocol reusable without altering the
// metadata behavior of any built-in database driver.
pub async fn list_constraints_core(
state: &AppState,
connection_id: &str,
database: &str,
schema: &str,
table: &str,
) -> Result<Vec<db::ConstraintInfo>, String> {
retry_metadata_connection(state, connection_id, Some(database), || async {
let pool_key = state.get_or_create_pool(connection_id, Some(database)).await?;
let db_config = connection_config(state, connection_id).await;
let connections = state.connections.read().await;
if let Some(client) = extract_pool!(&connections, &pool_key, Agent) {
drop(connections);
let mut client = client.lock().await;
return client.list_constraints(database, schema, table, agent_metadata_timeout(db_config.as_ref())).await;
}
Ok(vec![])
})
.await
}
pub async fn list_partitions_core(
state: &AppState,
connection_id: &str,
database: &str,
schema: &str,
table: &str,
) -> Result<Vec<db::PartitionInfo>, String> {
retry_metadata_connection(state, connection_id, Some(database), || async {
let pool_key = state.get_or_create_pool(connection_id, Some(database)).await?;
let db_config = connection_config(state, connection_id).await;
let connections = state.connections.read().await;
if let Some(client) = extract_pool!(&connections, &pool_key, Agent) {
drop(connections);
let mut client = client.lock().await;
return client.list_partitions(database, schema, table, agent_metadata_timeout(db_config.as_ref())).await;
}
Ok(vec![])
})
.await
}
pub async fn list_subpartitions_core(
state: &AppState,
connection_id: &str,
database: &str,
schema: &str,
table: &str,
) -> Result<Vec<db::SubpartitionInfo>, String> {
retry_metadata_connection(state, connection_id, Some(database), || async {
let pool_key = state.get_or_create_pool(connection_id, Some(database)).await?;
let db_config = connection_config(state, connection_id).await;
let connections = state.connections.read().await;
if let Some(client) = extract_pool!(&connections, &pool_key, Agent) {
drop(connections);
let mut client = client.lock().await;
return client
.list_subpartitions(database, schema, table, agent_metadata_timeout(db_config.as_ref()))
.await;
}
Ok(vec![])
})
.await
}
pub async fn list_functions_core(
state: &AppState,
connection_id: &str,
+53
View File
@@ -282,6 +282,59 @@ pub struct TriggerInfo {
pub statement: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConstraintInfo {
pub name: String,
pub constraint_type: String,
pub definition: String,
#[serde(default)]
pub columns: Vec<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ref_schema: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ref_table: Option<String>,
#[serde(default)]
pub ref_columns: Vec<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub match_type: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub on_update: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub on_delete: Option<String>,
#[serde(default)]
pub deferrable: bool,
#[serde(default)]
pub initially_deferred: bool,
#[serde(default)]
pub enabled: bool,
#[serde(default)]
pub valid: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PartitionInfo {
pub name: String,
pub position: i32,
pub value: String,
pub partition_type: String,
pub partition_key: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub online: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub auto_partition_type: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub auto_partition_span: Option<i32>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SubpartitionInfo {
pub name: String,
pub position: i32,
pub value: String,
pub partition_type: String,
pub partition_key: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FunctionInfo {