feat: extract dbx-core crate for web deployment support

Refactor all database drivers, query execution, schema operations, and
business logic into a shared `dbx-core` crate. The Tauri desktop app
becomes a thin shell delegating to dbx-core, enabling future web and
CLI frontends to reuse the same core.
This commit is contained in:
t8y2 committed 2026-05-05 03:16:24 +08:00
1 parent 7bee4bca55
commit cf4f25fd52
48 files changed
+15354 -4759

No files matched your search

+13 -78
View File
@@ -1,23 +1,15 @@
use std::sync::Arc;
use tauri::State;
use crate::commands::connection::{AppState, PoolKind};
use crate::db::redis_driver::{self, RedisScanResult, RedisValue};
use crate::commands::connection::AppState;
use dbx_core::db::redis_driver::{RedisScanResult, RedisValue};
#[tauri::command]
pub async fn redis_list_databases(
state: State<'_, Arc<AppState>>,
connection_id: String,
) -> Result<Vec<u32>, String> {
let connections = state.connections.lock().await;
let pool = connections.get(&connection_id).ok_or("Connection not found")?;
match pool {
PoolKind::Redis(con) => {
let mut con = con.lock().await;
redis_driver::list_databases(&mut con).await
}
_ => Err("Not a Redis connection".to_string()),
}
dbx_core::redis_ops::redis_list_databases_core(&state, &connection_id).await
}
#[tauri::command]
@@ -29,16 +21,7 @@ pub async fn redis_scan_keys(
pattern: String,
count: usize,
) -> Result<RedisScanResult, String> {
let connections = state.connections.lock().await;
let pool = connections.get(&connection_id).ok_or("Connection not found")?;
match pool {
PoolKind::Redis(con) => {
let mut con = con.lock().await;
redis_driver::select_db(&mut con, db).await?;
redis_driver::scan_keys_page(&mut con, cursor, &pattern, count).await
}
_ => Err("Not a Redis connection".to_string()),
}
dbx_core::redis_ops::redis_scan_keys_core(&state, &connection_id, db, cursor, &pattern, count).await
}
#[tauri::command]
@@ -47,15 +30,7 @@ pub async fn redis_get_value(
connection_id: String,
key: String,
) -> Result<RedisValue, String> {
let connections = state.connections.lock().await;
let pool = connections.get(&connection_id).ok_or("Connection not found")?;
match pool {
PoolKind::Redis(con) => {
let mut con = con.lock().await;
redis_driver::get_value(&mut con, &key).await
}
_ => Err("Not a Redis connection".to_string()),
}
dbx_core::redis_ops::redis_get_value_core(&state, &connection_id, &key).await
}
#[tauri::command]
@@ -66,15 +41,7 @@ pub async fn redis_set_string(
value: String,
ttl: Option<i64>,
) -> Result<(), String> {
let connections = state.connections.lock().await;
let pool = connections.get(&connection_id).ok_or("Connection not found")?;
match pool {
PoolKind::Redis(con) => {
let mut con = con.lock().await;
redis_driver::set_string(&mut con, &key, &value, ttl).await
}
_ => Err("Not a Redis connection".to_string()),
}
dbx_core::redis_ops::redis_set_string_core(&state, &connection_id, &key, &value, ttl).await
}
#[tauri::command]
@@ -83,15 +50,7 @@ pub async fn redis_delete_key(
connection_id: String,
key: String,
) -> Result<(), String> {
let connections = state.connections.lock().await;
let pool = connections.get(&connection_id).ok_or("Connection not found")?;
match pool {
PoolKind::Redis(con) => {
let mut con = con.lock().await;
redis_driver::delete_key(&mut con, &key).await
}
_ => Err("Not a Redis connection".to_string()),
}
dbx_core::redis_ops::redis_delete_key_core(&state, &connection_id, &key).await
}
#[tauri::command]
@@ -99,11 +58,7 @@ pub async fn redis_hash_set(
state: State<'_, Arc<AppState>>,
connection_id: String, key: String, field: String, value: String,
) -> Result<(), String> {
let connections = state.connections.lock().await;
match connections.get(&connection_id).ok_or("Not found")? {
PoolKind::Redis(con) => redis_driver::hash_set(&mut *con.lock().await, &key, &field, &value).await,
_ => Err("Not a Redis connection".to_string()),
}
dbx_core::redis_ops::redis_hash_set_core(&state, &connection_id, &key, &field, &value).await
}
#[tauri::command]
@@ -111,11 +66,7 @@ pub async fn redis_hash_del(
state: State<'_, Arc<AppState>>,
connection_id: String, key: String, field: String,
) -> Result<(), String> {
let connections = state.connections.lock().await;
match connections.get(&connection_id).ok_or("Not found")? {
PoolKind::Redis(con) => redis_driver::hash_del(&mut *con.lock().await, &key, &field).await,
_ => Err("Not a Redis connection".to_string()),
}
dbx_core::redis_ops::redis_hash_del_core(&state, &connection_id, &key, &field).await
}
#[tauri::command]
@@ -123,11 +74,7 @@ pub async fn redis_list_push(
state: State<'_, Arc<AppState>>,
connection_id: String, key: String, value: String,
) -> Result<(), String> {
let connections = state.connections.lock().await;
match connections.get(&connection_id).ok_or("Not found")? {
PoolKind::Redis(con) => redis_driver::list_push(&mut *con.lock().await, &key, &value).await,
_ => Err("Not a Redis connection".to_string()),
}
dbx_core::redis_ops::redis_list_push_core(&state, &connection_id, &key, &value).await
}
#[tauri::command]
@@ -135,11 +82,7 @@ pub async fn redis_list_remove(
state: State<'_, Arc<AppState>>,
connection_id: String, key: String, index: i64,
) -> Result<(), String> {
let connections = state.connections.lock().await;
match connections.get(&connection_id).ok_or("Not found")? {
PoolKind::Redis(con) => redis_driver::list_remove(&mut *con.lock().await, &key, index).await,
_ => Err("Not a Redis connection".to_string()),
}
dbx_core::redis_ops::redis_list_remove_core(&state, &connection_id, &key, index).await
}
#[tauri::command]
@@ -147,11 +90,7 @@ pub async fn redis_set_add(
state: State<'_, Arc<AppState>>,
connection_id: String, key: String, member: String,
) -> Result<(), String> {
let connections = state.connections.lock().await;
match connections.get(&connection_id).ok_or("Not found")? {
PoolKind::Redis(con) => redis_driver::set_add(&mut *con.lock().await, &key, &member).await,
_ => Err("Not a Redis connection".to_string()),
}
dbx_core::redis_ops::redis_set_add_core(&state, &connection_id, &key, &member).await
}
#[tauri::command]
@@ -159,9 +98,5 @@ pub async fn redis_set_remove(
state: State<'_, Arc<AppState>>,
connection_id: String, key: String, member: String,
) -> Result<(), String> {
let connections = state.connections.lock().await;
match connections.get(&connection_id).ok_or("Not found")? {
PoolKind::Redis(con) => redis_driver::set_remove(&mut *con.lock().await, &key, &member).await,
_ => Err("Not a Redis connection".to_string()),
}
dbx_core::redis_ops::redis_set_remove_core(&state, &connection_id, &key, &member).await
}