25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
feat: refactor Oracle database handling to use OracleClient instead of OraclePool
t8y2125793bd6260
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lockindex bc3964a8e1..c286c7a39c 100644--- a/src-tauri/Cargo.lock+++ b/src-tauri/Cargo.lock@@ -1119,6 +1119,7 @@ dependencies = ["log","mongodb","oracle-rs",+ "percent-encoding","portpicker","redis","reqwest 0.12.28",diff --git a/src-tauri/src/commands/connection.rs b/src-tauri/src/commands/connection.rsindex ac2693afad..d167a95420 100644--- a/src-tauri/src/commands/connection.rs+++ b/src-tauri/src/commands/connection.rs@@ -16,7 +16,7 @@ pub enum PoolKind {MongoDb(mongodb::Client),ClickHouse(db::clickhouse_driver::ChClient),SqlServer(std::sync::Arc<tokio::sync::Mutex<db::sqlserver::SqlServerClient>>),- Oracle(std::sync::Arc<tokio::sync::Mutex<db::oracle_driver::OraclePool>>),+ Oracle(std::sync::Arc<tokio::sync::Mutex<db::oracle_driver::OracleClient>>),}pub struct AppState {@@ -110,12 +110,12 @@ impl AppState {PoolKind::SqlServer(std::sync::Arc::new(tokio::sync::Mutex::new(client)))}DatabaseType::Oracle => {- let pool = db::oracle_driver::OraclePool::connect(+ let client = db::oracle_driver::connect(&db_config.host, db_config.port,db_config.database.as_deref().unwrap_or("ORCL"),&db_config.username, &db_config.password,).await?;- PoolKind::Oracle(std::sync::Arc::new(tokio::sync::Mutex::new(pool)))+ PoolKind::Oracle(std::sync::Arc::new(tokio::sync::Mutex::new(client)))}};@@ -222,7 +222,7 @@ pub async fn test_connection(config: ConnectionConfig) -> Result<String, String>Ok("Connection successful".to_string())}DatabaseType::Oracle => {- let _pool = db::oracle_driver::OraclePool::connect(+ let _client = db::oracle_driver::connect(&config.host, config.port,config.database.as_deref().unwrap_or("ORCL"),&config.username, &config.password,@@ -279,12 +279,12 @@ pub async fn connect_db().await?;PoolKind::SqlServer(std::sync::Arc::new(tokio::sync::Mutex::new(client))) }DatabaseType::Oracle => {- let pool = db::oracle_driver::OraclePool::connect(+ let client = db::oracle_driver::connect(&config.host, config.port,config.database.as_deref().unwrap_or("ORCL"),&config.username, &config.password,).await?;- PoolKind::Oracle(std::sync::Arc::new(tokio::sync::Mutex::new(pool)))+ PoolKind::Oracle(std::sync::Arc::new(tokio::sync::Mutex::new(client)))}};diff --git a/src-tauri/src/commands/query.rs b/src-tauri/src/commands/query.rsindex bfa67d5caf..6256d28de5 100644--- a/src-tauri/src/commands/query.rs+++ b/src-tauri/src/commands/query.rs@@ -132,11 +132,11 @@ async fn do_execute(.map_err(|_| format!("Query timed out after {} seconds", QUERY_TIMEOUT.as_secs()))?.map(truncate_result)}- PoolKind::Oracle(pool) => {- let pool = pool.clone();+ PoolKind::Oracle(client) => {+ let client = client.clone();drop(connections);- let mut pool = pool.lock().await;- timeout(QUERY_TIMEOUT, db::oracle_driver::execute_query(&mut pool, sql))+ let client = client.lock().await;+ timeout(QUERY_TIMEOUT, db::oracle_driver::execute_query(&*client, sql)).await.map_err(|_| format!("Query timed out after {} seconds", QUERY_TIMEOUT.as_secs()))?.map(truncate_result)diff --git a/src-tauri/src/commands/schema.rs b/src-tauri/src/commands/schema.rsindex fd79f65843..9e4fc22145 100644--- a/src-tauri/src/commands/schema.rs+++ b/src-tauri/src/commands/schema.rs@@ -75,9 +75,9 @@ fn extract_clickhouse(connections: &std::collections::HashMap<String, PoolKind>,}}-fn extract_oracle(connections: &std::collections::HashMap<String, PoolKind>, key: &str) -> Option<std::sync::Arc<tokio::sync::Mutex<db::oracle_driver::OraclePool>>> {+fn extract_oracle(connections: &std::collections::HashMap<String, PoolKind>, key: &str) -> Option<std::sync::Arc<tokio::sync::Mutex<db::oracle_driver::OracleClient>>> {match connections.get(key)? {- PoolKind::Oracle(pool) => Some(pool.clone()),+ PoolKind::Oracle(client) => Some(client.clone()),_ => None,}}@@ -98,10 +98,10 @@ pub async fn list_databases(let mut client = client.lock().await;return db::sqlserver::list_databases(&mut client).await;}- if let Some(pool) = extract_oracle(&connections, &connection_id) {+ if let Some(client) = extract_oracle(&connections, &connection_id) {drop(connections);- let pool = pool.lock().await;- return db::oracle_driver::list_databases(&pool).await;+ let client = client.lock().await;+ return db::oracle_driver::list_databases(&*client).await;}}@@ -132,10 +132,10 @@ pub async fn list_schemas(let mut client = client.lock().await;return db::sqlserver::list_schemas(&mut client).await;}- if let Some(pool) = extract_oracle(&connections, &pool_key) {+ if let Some(client) = extract_oracle(&connections, &pool_key) {drop(connections);- let pool = pool.lock().await;- return db::oracle_driver::list_schemas(&pool).await;+ let client = client.lock().await;+ return db::oracle_driver::list_schemas(&*client).await;}}@@ -173,10 +173,10 @@ pub async fn list_tables(let mut client = client.lock().await;return db::sqlserver::list_tables(&mut client, &schema).await;}- if let Some(pool) = extract_oracle(&connections, &pool_key) {+ if let Some(client) = extract_oracle(&connections, &pool_key) {drop(connections);- let pool = pool.lock().await;- return db::oracle_driver::list_tables(&pool, &schema).await;+ let client = client.lock().await;+ return db::oracle_driver::list_tables(&*client, &schema).await;}}@@ -217,10 +217,10 @@ pub async fn get_columns(let mut client = client.lock().await;return db::sqlserver::get_columns(&mut client, &schema, &table).await;}- if let Some(pool) = extract_oracle(&connections, &pool_key) {+ if let Some(client) = extract_oracle(&connections, &pool_key) {drop(connections);- let pool = pool.lock().await;- return db::oracle_driver::get_columns(&pool, &schema, &table).await;+ let client = client.lock().await;+ return db::oracle_driver::get_columns(&*client, &schema, &table).await;}}@@ -252,10 +252,10 @@ pub async fn list_indexes(let mut client = client.lock().await;return db::sqlserver::list_indexes(&mut client, &schema, &table).await;}- if let Some(pool) = extract_oracle(&connections, &pool_key) {+ if let Some(client) = extract_oracle(&connections, &pool_key) {drop(connections);- let pool = pool.lock().await;- return db::oracle_driver::list_indexes(&pool, &schema, &table).await;+ let client = client.lock().await;+ return db::oracle_driver::list_indexes(&*client, &schema, &table).await;}}@@ -287,10 +287,10 @@ pub async fn list_foreign_keys(let mut client = client.lock().await;return db::sqlserver::list_foreign_keys(&mut client, &schema, &table).await;}- if let Some(pool) = extract_oracle(&connections, &pool_key) {+ if let Some(client) = extract_oracle(&connections, &pool_key) {drop(connections);- let pool = pool.lock().await;- return db::oracle_driver::list_foreign_keys(&pool, &schema, &table).await;+ let client = client.lock().await;+ return db::oracle_driver::list_foreign_keys(&*client, &schema, &table).await;}}@@ -322,10 +322,10 @@ pub async fn list_triggers(let mut client = client.lock().await;return db::sqlserver::list_triggers(&mut client, &schema, &table).await;}- if let Some(pool) = extract_oracle(&connections, &pool_key) {+ if let Some(client) = extract_oracle(&connections, &pool_key) {drop(connections);- let pool = pool.lock().await;- return db::oracle_driver::list_triggers(&pool, &schema, &table).await;+ let client = client.lock().await;+ return db::oracle_driver::list_triggers(&*client, &schema, &table).await;}}@@ -378,10 +378,10 @@ pub async fn get_table_ddl(let mut client = client.lock().await;return build_sqlserver_ddl(&mut client, &schema, &table).await;}- if let Some(pool) = extract_oracle(&connections, &pool_key) {+ if let Some(client) = extract_oracle(&connections, &pool_key) {drop(connections);- let pool = pool.lock().await;- return build_oracle_ddl(&pool, &schema, &table).await;+ let client = client.lock().await;+ return build_oracle_ddl(&*client, &schema, &table).await;}}@@ -477,10 +477,10 @@ async fn build_sqlserver_ddl(client: &mut db::sqlserver::SqlServerClient, schemaOk(ddl)}-async fn build_oracle_ddl(pool: &db::oracle_driver::OraclePool, schema: &str, table: &str) -> Result<String, String> {- let columns = db::oracle_driver::get_columns(pool, schema, table).await?;- let indexes = db::oracle_driver::list_indexes(pool, schema, table).await?;- let fkeys = db::oracle_driver::list_foreign_keys(pool, schema, table).await?;+async fn build_oracle_ddl(client: &db::oracle_driver::OracleClient, schema: &str, table: &str) -> Result<String, String> {+ let columns = db::oracle_driver::get_columns(client, schema, table).await?;+ let indexes = db::oracle_driver::list_indexes(client, schema, table).await?;+ let fkeys = db::oracle_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| {diff --git a/src-tauri/src/db/oracle_driver.rs b/src-tauri/src/db/oracle_driver.rsindex bf71cca996..4eeb9e8aa7 100644--- a/src-tauri/src/db/oracle_driver.rs+++ b/src-tauri/src/db/oracle_driver.rs@@ -3,38 +3,13 @@ use std::time::Instant;use super::{ColumnInfo, DatabaseInfo, ForeignKeyInfo, IndexInfo, QueryResult, TableInfo, TriggerInfo};-pub struct OraclePool {- pub conn: Connection,- host: String,- port: u16,- service: String,- user: String,- pass: String,-}--impl OraclePool {- pub async fn connect(host: &str, port: u16, service: &str, user: &str, pass: &str) -> Result<Self, String> {- let config = Config::new(host, port, service, user, pass);- let conn = Connection::connect_with_config(config)- .await- .map_err(|e| format!("Oracle connection failed: {e}"))?;- Ok(Self {- conn,- host: host.to_string(),- port,- service: service.to_string(),- user: user.to_string(),- pass: pass.to_string(),- })- }+pub type OracleClient = Connection;- pub async fn reconnect(&mut self) -> Result<(), String> {- let config = Config::new(&self.host, self.port, &self.service, &self.user, &self.pass);- self.conn = Connection::connect_with_config(config)- .await- .map_err(|e| format!("Oracle reconnect failed: {e}"))?;- Ok(())- }+pub async fn connect(host: &str, port: u16, service: &str, user: &str, pass: &str) -> Result<OracleClient, String> {+ let config = Config::new(host, port, service, user, pass);+ Connection::connect_with_config(config)+ .await+ .map_err(|e| format!("Oracle connection failed: {e}"))}fn value_to_json(val: &oracle_rs::Value) -> serde_json::Value {@@ -51,20 +26,18 @@ fn value_to_json(val: &oracle_rs::Value) -> serde_json::Value {}}-pub async fn list_databases(pool: &OraclePool) -> Result<Vec<DatabaseInfo>, String> {- let result = pool.conn.query(+pub async fn list_databases(conn: &OracleClient) -> Result<Vec<DatabaseInfo>, String> {+ let result = conn.query("SELECT username FROM all_users ORDER BY username",&[],).await.map_err(|e| e.to_string())?;Ok(result.rows.iter().map(|row| {- DatabaseInfo {- name: row.get_string(0).unwrap_or("").to_string(),- }+ DatabaseInfo { name: row.get_string(0).unwrap_or("").to_string() }}).collect())}-pub async fn list_schemas(pool: &OraclePool) -> Result<Vec<String>, String> {- let result = pool.conn.query(+pub async fn list_schemas(conn: &OracleClient) -> Result<Vec<String>, String> {+ let result = conn.query("SELECT username FROM all_users ORDER BY username",&[],).await.map_err(|e| e.to_string())?;@@ -73,7 +46,7 @@ pub async fn list_schemas(pool: &OraclePool) -> Result<Vec<String>, String> {}).collect())}-pub async fn list_tables(pool: &OraclePool, schema: &str) -> Result<Vec<TableInfo>, String> {+pub async fn list_tables(conn: &OracleClient, schema: &str) -> Result<Vec<TableInfo>, String> {let sql = format!("SELECT table_name, 'TABLE' AS table_type FROM all_tables WHERE owner = '{s}' \UNION ALL \@@ -81,7 +54,7 @@ pub async fn list_tables(pool: &OraclePool, schema: &str) -> Result<Vec<TableInfORDER BY 1",s = schema.replace('\'', "''"));- let result = pool.conn.query(&sql, &[]).await.map_err(|e| e.to_string())?;+ let result = conn.query(&sql, &[]).await.map_err(|e| e.to_string())?;Ok(result.rows.iter().map(|row| {TableInfo {name: row.get_string(0).unwrap_or("").to_string(),@@ -90,11 +63,11 @@ pub async fn list_tables(pool: &OraclePool, schema: &str) -> Result<Vec<TableInf}).collect())}-pub async fn get_columns(pool: &OraclePool, schema: &str, table: &str) -> Result<Vec<ColumnInfo>, String> {+pub async fn get_columns(conn: &OracleClient, schema: &str, table: &str) -> Result<Vec<ColumnInfo>, String> {let s = schema.replace('\'', "''");let t = table.replace('\'', "''");- let pk_result = pool.conn.query(+ let pk_result = conn.query(&format!("SELECT cols.COLUMN_NAME FROM ALL_CONS_COLUMNS cols \JOIN ALL_CONSTRAINTS cons ON cols.CONSTRAINT_NAME = cons.CONSTRAINT_NAME AND cols.OWNER = cons.OWNER \@@ -106,7 +79,7 @@ pub async fn get_columns(pool: &OraclePool, schema: &str, table: &str) -> Result.filter_map(|row| row.get_string(0).map(|s| s.to_string())).collect();- let col_result = pool.conn.query(+ let col_result = conn.query(&format!("SELECT COLUMN_NAME, DATA_TYPE, NULLABLE \FROM ALL_TAB_COLUMNS \@@ -129,7 +102,7 @@ pub async fn get_columns(pool: &OraclePool, schema: &str, table: &str) -> Result}).collect())}-pub async fn list_indexes(pool: &OraclePool, schema: &str, table: &str) -> Result<Vec<IndexInfo>, String> {+pub async fn list_indexes(conn: &OracleClient, schema: &str, table: &str) -> Result<Vec<IndexInfo>, String> {let sql = format!("SELECT i.INDEX_NAME, \LISTAGG(ic.COLUMN_NAME, ',') WITHIN GROUP (ORDER BY ic.COLUMN_POSITION) AS columns, \@@ -144,7 +117,7 @@ pub async fn list_indexes(pool: &OraclePool, schema: &str, table: &str) -> ResulORDER BY i.INDEX_NAME",s = schema.replace('\'', "''"), t = table.replace('\'', "''"));- let result = pool.conn.query(&sql, &[]).await.map_err(|e| e.to_string())?;+ let result = conn.query(&sql, &[]).await.map_err(|e| e.to_string())?;Ok(result.rows.iter().map(|row| {let cols_str = row.get_string(1).unwrap_or("");IndexInfo {@@ -156,7 +129,7 @@ pub async fn list_indexes(pool: &OraclePool, schema: &str, table: &str) -> Resul}).collect())}-pub async fn list_foreign_keys(pool: &OraclePool, schema: &str, table: &str) -> Result<Vec<ForeignKeyInfo>, String> {+pub async fn list_foreign_keys(conn: &OracleClient, schema: &str, table: &str) -> Result<Vec<ForeignKeyInfo>, String> {let sql = format!("SELECT c.CONSTRAINT_NAME, cc.COLUMN_NAME, rc.TABLE_NAME, rcc.COLUMN_NAME \FROM ALL_CONSTRAINTS c \@@ -167,7 +140,7 @@ pub async fn list_foreign_keys(pool: &OraclePool, schema: &str, table: &str) ->ORDER BY c.CONSTRAINT_NAME",s = schema.replace('\'', "''"), t = table.replace('\'', "''"));- let result = pool.conn.query(&sql, &[]).await.map_err(|e| e.to_string())?;+ let result = conn.query(&sql, &[]).await.map_err(|e| e.to_string())?;Ok(result.rows.iter().map(|row| {ForeignKeyInfo {name: row.get_string(0).unwrap_or("").to_string(),@@ -178,7 +151,7 @@ pub async fn list_foreign_keys(pool: &OraclePool, schema: &str, table: &str) ->}).collect())}-pub async fn list_triggers(pool: &OraclePool, schema: &str, table: &str) -> Result<Vec<TriggerInfo>, String> {+pub async fn list_triggers(conn: &OracleClient, schema: &str, table: &str) -> Result<Vec<TriggerInfo>, String> {let sql = format!("SELECT TRIGGER_NAME, TRIGGERING_EVENT, TRIGGER_TYPE \FROM ALL_TRIGGERS \@@ -186,7 +159,7 @@ pub async fn list_triggers(pool: &OraclePool, schema: &str, table: &str) -> ResuORDER BY TRIGGER_NAME",s = schema.replace('\'', "''"), t = table.replace('\'', "''"));- let result = pool.conn.query(&sql, &[]).await.map_err(|e| e.to_string())?;+ let result = conn.query(&sql, &[]).await.map_err(|e| e.to_string())?;Ok(result.rows.iter().map(|row| {TriggerInfo {name: row.get_string(0).unwrap_or("").to_string(),@@ -196,7 +169,7 @@ pub async fn list_triggers(pool: &OraclePool, schema: &str, table: &str) -> Resu}).collect())}-pub async fn execute_query(pool: &mut OraclePool, sql: &str) -> Result<QueryResult, String> {+pub async fn execute_query(conn: &OracleClient, sql: &str) -> Result<QueryResult, String> {let start = Instant::now();let sql = sql.trim().trim_end_matches(';');let trimmed = sql.to_uppercase();@@ -207,7 +180,7 @@ pub async fn execute_query(pool: &mut OraclePool, sql: &str) -> Result<QueryResu|| trimmed.starts_with("DESCRIBE")|| trimmed.starts_with("EXPLAIN"){- let result = pool.conn.query(sql, &[]).await.map_err(|e| e.to_string())?;+ let result = conn.query(sql, &[]).await.map_err(|e| e.to_string())?;let columns: Vec<String> = result.columns.iter().map(|c| c.name.clone()).collect();let rows: Vec<Vec<serde_json::Value>> = result.rows.iter().map(|row| {(0..columns.len()).map(|i| {@@ -225,9 +198,9 @@ pub async fn execute_query(pool: &mut OraclePool, sql: &str) -> Result<QueryResutruncated: false,})} else {- match pool.conn.execute(sql, &[]).await {+ match conn.execute(sql, &[]).await {Ok(result) => {- pool.conn.commit().await.map_err(|e| e.to_string())?;+ let _ = conn.commit().await;Ok(QueryResult {columns: vec![],rows: vec![],@@ -239,7 +212,6 @@ pub async fn execute_query(pool: &mut OraclePool, sql: &str) -> Result<QueryResuErr(e) => {let msg = e.to_string();if msg.contains("Server rejected") || msg.contains("closed the connection") {- let _ = pool.reconnect().await;Err("Operation failed — possibly a constraint violation (foreign key, unique, or check constraint).".to_string())} else {Err(msg)