feat: add 12 new agent-driven databases, migrate GaussDB to agent
Add H2, Snowflake, Trino, Hive, DB2, Informix, Neo4j, Cassandra, BigQuery, Apache Kylin, SunDB as new agent-driven database types. Migrate GaussDB from native rust-gaussdb to JDBC agent. Remove rust-gaussdb dependency. Total agent-driven databases: 17.
This commit is contained in:
1 parent
c50323cd6c
commit
7ce2cf2163
16 files changed
+245
-574
No files matched your search
@@ -112,16 +112,6 @@ pub fn extract_agent(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extract_gaussdb(
|
||||
connections: &HashMap<String, PoolKind>,
|
||||
key: &str,
|
||||
) -> Option<Arc<tokio::sync::Mutex<db::gaussdb_driver::GaussdbClient>>> {
|
||||
match connections.get(key)? {
|
||||
PoolKind::Gaussdb(client) => Some(client.clone()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn list_databases_core(state: &AppState, connection_id: &str) -> Result<Vec<db::DatabaseInfo>, String> {
|
||||
{
|
||||
let connections = state.connections.read().await;
|
||||
@@ -150,11 +140,6 @@ pub async fn list_databases_core(state: &AppState, connection_id: &str) -> Resul
|
||||
let mut client = client.lock().await;
|
||||
return client.call("list_databases", serde_json::json!({})).await;
|
||||
}
|
||||
if let Some(client) = extract_gaussdb(&connections, connection_id) {
|
||||
drop(connections);
|
||||
let mut client = client.lock().await;
|
||||
return db::gaussdb_driver::list_databases(&mut client).await;
|
||||
}
|
||||
}
|
||||
|
||||
let connections = state.connections.read().await;
|
||||
@@ -198,11 +183,6 @@ pub async fn list_schemas_core(state: &AppState, connection_id: &str, database:
|
||||
let mut client = client.lock().await;
|
||||
return client.call("list_schemas", serde_json::json!({"database": database})).await;
|
||||
}
|
||||
if let Some(client) = extract_gaussdb(&connections, &pool_key) {
|
||||
drop(connections);
|
||||
let mut client = client.lock().await;
|
||||
return db::gaussdb_driver::list_schemas(&mut client).await;
|
||||
}
|
||||
}
|
||||
|
||||
let connections = state.connections.read().await;
|
||||
@@ -264,11 +244,6 @@ pub async fn list_tables_core(
|
||||
let mut client = client.lock().await;
|
||||
return client.call("list_tables", serde_json::json!({"schema": schema})).await;
|
||||
}
|
||||
if let Some(client) = extract_gaussdb(&connections, &pool_key) {
|
||||
drop(connections);
|
||||
let mut client = client.lock().await;
|
||||
return db::gaussdb_driver::list_tables(&mut client, schema).await;
|
||||
}
|
||||
}
|
||||
|
||||
let connections = state.connections.read().await;
|
||||
@@ -392,11 +367,6 @@ pub async fn get_columns_core(
|
||||
let mut client = client.lock().await;
|
||||
return client.call("get_columns", serde_json::json!({"schema": schema, "table": table})).await;
|
||||
}
|
||||
if let Some(client) = extract_gaussdb(&connections, &pool_key) {
|
||||
drop(connections);
|
||||
let mut client = client.lock().await;
|
||||
return db::gaussdb_driver::get_columns(&mut client, schema, table).await;
|
||||
}
|
||||
}
|
||||
|
||||
let connections = state.connections.read().await;
|
||||
@@ -437,11 +407,6 @@ pub async fn list_indexes_core(
|
||||
let mut client = client.lock().await;
|
||||
return client.call("list_indexes", serde_json::json!({"schema": schema, "table": table})).await;
|
||||
}
|
||||
if let Some(client) = extract_gaussdb(&connections, &pool_key) {
|
||||
drop(connections);
|
||||
let mut client = client.lock().await;
|
||||
return db::gaussdb_driver::list_indexes(&mut client, schema, table).await;
|
||||
}
|
||||
}
|
||||
|
||||
let connections = state.connections.read().await;
|
||||
@@ -482,11 +447,6 @@ pub async fn list_foreign_keys_core(
|
||||
let mut client = client.lock().await;
|
||||
return client.call("list_foreign_keys", serde_json::json!({"schema": schema, "table": table})).await;
|
||||
}
|
||||
if let Some(client) = extract_gaussdb(&connections, &pool_key) {
|
||||
drop(connections);
|
||||
let mut client = client.lock().await;
|
||||
return db::gaussdb_driver::list_foreign_keys(&mut client, schema, table).await;
|
||||
}
|
||||
}
|
||||
|
||||
let connections = state.connections.read().await;
|
||||
@@ -527,11 +487,6 @@ pub async fn list_triggers_core(
|
||||
let mut client = client.lock().await;
|
||||
return client.call("list_triggers", serde_json::json!({"schema": schema, "table": table})).await;
|
||||
}
|
||||
if let Some(client) = extract_gaussdb(&connections, &pool_key) {
|
||||
drop(connections);
|
||||
let mut client = client.lock().await;
|
||||
return db::gaussdb_driver::list_triggers(&mut client, schema, table).await;
|
||||
}
|
||||
}
|
||||
|
||||
let connections = state.connections.read().await;
|
||||
@@ -598,11 +553,6 @@ pub async fn get_table_ddl_core(
|
||||
let mut client = client.lock().await;
|
||||
return client.call("get_table_ddl", serde_json::json!({"schema": schema, "table": table})).await;
|
||||
}
|
||||
if let Some(client) = extract_gaussdb(&connections, &pool_key) {
|
||||
drop(connections);
|
||||
let mut client = client.lock().await;
|
||||
return build_gaussdb_ddl(&mut client, schema, table).await;
|
||||
}
|
||||
}
|
||||
|
||||
let connections = state.connections.read().await;
|
||||
@@ -747,13 +697,6 @@ pub async fn get_object_source_core(
|
||||
db::sqlserver::execute_query(&mut client, &sqlserver_object_source_sql(schema, name, &object_type))
|
||||
.await?,
|
||||
)?
|
||||
} else if let Some(client) = extract_gaussdb(&connections, &pool_key) {
|
||||
drop(connections);
|
||||
let mut client = client.lock().await;
|
||||
first_string_cell(
|
||||
db::gaussdb_driver::execute_query(&mut client, &postgres_object_source_sql(schema, name, &object_type))
|
||||
.await?,
|
||||
)?
|
||||
} else {
|
||||
match connections.get(&pool_key).ok_or("Pool not found")? {
|
||||
PoolKind::Mysql(pool, _) => mysql_object_source(pool, name, &object_type).await?,
|
||||
@@ -964,54 +907,3 @@ pub async fn build_sqlserver_ddl(
|
||||
}
|
||||
Ok(ddl)
|
||||
}
|
||||
|
||||
pub async fn build_gaussdb_ddl(
|
||||
client: &mut db::gaussdb_driver::GaussdbClient,
|
||||
schema: &str,
|
||||
table: &str,
|
||||
) -> Result<String, String> {
|
||||
let columns = db::gaussdb_driver::get_columns(client, schema, table).await?;
|
||||
let indexes = db::gaussdb_driver::list_indexes(client, schema, table).await?;
|
||||
let fkeys = db::gaussdb_driver::list_foreign_keys(client, schema, table).await?;
|
||||
|
||||
let mut ddl = format!("CREATE TABLE \"{schema}\".\"{table}\" (\n");
|
||||
let col_lines: Vec<String> = columns
|
||||
.iter()
|
||||
.map(|c| {
|
||||
let mut line = format!(" \"{}\" {}", c.name, c.data_type);
|
||||
if !c.is_nullable {
|
||||
line.push_str(" NOT NULL");
|
||||
}
|
||||
if let Some(ref def) = c.column_default {
|
||||
line.push_str(&format!(" DEFAULT {def}"));
|
||||
}
|
||||
line
|
||||
})
|
||||
.collect();
|
||||
ddl.push_str(&col_lines.join(",\n"));
|
||||
|
||||
let pks: Vec<&str> = columns.iter().filter(|c| c.is_primary_key).map(|c| c.name.as_str()).collect();
|
||||
if !pks.is_empty() {
|
||||
ddl.push_str(&format!(
|
||||
",\n PRIMARY KEY ({})",
|
||||
pks.iter().map(|k| format!("\"{k}\"")).collect::<Vec<_>>().join(", ")
|
||||
));
|
||||
}
|
||||
for fk in &fkeys {
|
||||
ddl.push_str(&format!(
|
||||
",\n CONSTRAINT \"{}\" FOREIGN KEY (\"{}\") REFERENCES \"{}\"(\"{}\")",
|
||||
fk.name, fk.column, fk.ref_table, fk.ref_column
|
||||
));
|
||||
}
|
||||
ddl.push_str("\n);\n");
|
||||
|
||||
for idx in &indexes {
|
||||
if idx.is_primary {
|
||||
continue;
|
||||
}
|
||||
let unique = if idx.is_unique { "UNIQUE " } else { "" };
|
||||
let cols = idx.columns.iter().map(|c| format!("\"{c}\"")).collect::<Vec<_>>().join(", ");
|
||||
ddl.push_str(&format!("\nCREATE {unique}INDEX \"{}\" ON \"{schema}\".\"{table}\" ({cols});", idx.name));
|
||||
}
|
||||
Ok(ddl)
|
||||
}
|
||||
Reference in new issue
Block a user