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
use std::sync::Arc;
use axum::extract::{Path, State};
use axum::Json;
use dbx_core::saved_sql::{SavedSqlFile, SavedSqlFolder, SavedSqlLibrary};
use crate::error::AppError;
use crate::state::WebState;
pub async fn load_saved_sql_library(State(state): State<Arc<WebState>>) -> Result<Json<SavedSqlLibrary>, AppError> {
let library = state.app.storage.load_saved_sql_library_summary().await.map_err(AppError::from)?;
Ok(Json(library))
}
pub async fn load_saved_sql_file(
State(state): State<Arc<WebState>>,
Path(id): Path<String>,
) -> Result<Json<Option<SavedSqlFile>>, AppError> {
let file = state.app.storage.load_saved_sql_file(&id).await.map_err(AppError::from)?;
Ok(Json(file))
}
pub async fn save_saved_sql_folder(
State(state): State<Arc<WebState>>,
Json(folder): Json<SavedSqlFolder>,
) -> Result<Json<SavedSqlFolder>, AppError> {
state.app.storage.save_saved_sql_folder(&folder).await.map_err(AppError::from)?;
Ok(Json(folder))
}
pub async fn delete_saved_sql_folder(
State(state): State<Arc<WebState>>,
Path(id): Path<String>,
) -> Result<Json<()>, AppError> {
state.app.storage.delete_saved_sql_folder(&id).await.map_err(AppError::from)?;
Ok(Json(()))
}
pub async fn save_saved_sql_file(
State(state): State<Arc<WebState>>,
Json(file): Json<SavedSqlFile>,
) -> Result<Json<SavedSqlFile>, AppError> {
state.app.storage.save_saved_sql_file(&file).await.map_err(AppError::from)?;
Ok(Json(file))
}
pub async fn delete_saved_sql_file(
State(state): State<Arc<WebState>>,
Path(id): Path<String>,
) -> Result<Json<()>, AppError> {
state.app.storage.delete_saved_sql_file(&id).await.map_err(AppError::from)?;
Ok(Json(()))
}
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DefaultQueryContent {
sql: String,
updated_at: String,
}
pub async fn save_default_query_content(
State(state): State<Arc<WebState>>,
Path(id): Path<String>,
Json(content): Json<DefaultQueryContent>,
) -> Result<Json<()>, AppError> {
state
.app
.storage
.save_default_query_content(&id, &content.sql, &content.updated_at)
.await
.map_err(AppError::from)?;
Ok(Json(()))
}