perf(tauri): split schema command registry into crate

This commit is contained in:
luo jiyin authored and GitHub committed 2026-09-29 01:20:17 +08:00
1 parent 0be8a38984
commit 1aebef392d
9 files changed
+123 -53

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
[package]
name = "dbx-tauri-schema"
version = "0.1.0"
edition = "2021"
rust-version = "1.88.0"
[dependencies]
dbx-core = { path = "../dbx-core", default-features = false }
tauri = "2.10.3"
+685
View File
@@ -0,0 +1,685 @@
use std::sync::Arc;
use tauri::State;
use dbx_core::connection::AppState;
use dbx_core::db;
/// Resolve a non-internal catalog for dispatch to the Doris multi-catalog path.
/// Thin wrapper around the shared dbx-core resolver so the Tauri and HTTP
/// backends stay in sync.
async fn external_doris_catalog(state: &AppState, connection_id: &str, catalog: Option<&str>) -> Option<String> {
dbx_core::schema::resolve_external_doris_catalog(state, connection_id, catalog).await
}
#[tauri::command]
pub async fn list_databases(
state: State<'_, Arc<AppState>>,
connection_id: String,
) -> Result<Vec<db::DatabaseInfo>, String> {
dbx_core::schema::list_databases_core(&state, &connection_id).await
}
#[tauri::command]
pub async fn list_database_metadata(
state: State<'_, Arc<AppState>>,
connection_id: String,
) -> Result<Vec<db::DatabaseInfo>, String> {
dbx_core::schema::list_database_metadata_core(&state, &connection_id).await
}
#[tauri::command]
pub async fn list_database_storage(
state: State<'_, Arc<AppState>>,
connection_id: String,
databases: Vec<String>,
) -> Result<Vec<db::DatabaseStorageInfo>, String> {
dbx_core::schema::list_database_storage_core(&state, &connection_id, &databases).await
}
#[tauri::command]
pub async fn list_xugu_tablespaces(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: Option<String>,
) -> Result<Vec<db::XuguTablespaceInfo>, String> {
dbx_core::schema::list_xugu_tablespaces_core(&state, &connection_id, database.as_deref()).await
}
#[tauri::command]
pub async fn get_sqlserver_completion_context(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
) -> Result<db::sqlserver::SqlServerCompletionContext, String> {
dbx_core::schema::get_sqlserver_completion_context_core(&state, &connection_id, &database).await
}
#[tauri::command]
pub async fn list_doris_catalogs(
state: State<'_, Arc<AppState>>,
connection_id: String,
) -> Result<Vec<db::CatalogInfo>, String> {
dbx_core::schema::list_doris_catalogs_core(&state, &connection_id).await
}
#[tauri::command]
pub async fn list_doris_catalog_databases(
state: State<'_, Arc<AppState>>,
connection_id: String,
catalog: String,
) -> Result<Vec<db::DatabaseInfo>, String> {
dbx_core::schema::list_doris_catalog_databases_core(&state, &connection_id, &catalog).await
}
#[tauri::command]
pub async fn list_sqlserver_linked_servers(
state: State<'_, Arc<AppState>>,
connection_id: String,
) -> Result<Vec<db::LinkedServerInfo>, String> {
dbx_core::schema::list_sqlserver_linked_servers_core(&state, &connection_id).await
}
#[tauri::command]
pub async fn list_sqlserver_linked_server_catalogs(
state: State<'_, Arc<AppState>>,
connection_id: String,
server: String,
) -> Result<Vec<db::DatabaseInfo>, String> {
dbx_core::schema::list_sqlserver_linked_server_catalogs_core(&state, &connection_id, &server).await
}
#[tauri::command]
pub async fn list_sqlserver_linked_server_schemas(
state: State<'_, Arc<AppState>>,
connection_id: String,
server: String,
catalog: String,
) -> Result<Vec<String>, String> {
dbx_core::schema::list_sqlserver_linked_server_schemas_core(&state, &connection_id, &server, &catalog).await
}
#[tauri::command]
pub async fn list_sqlserver_linked_server_tables(
state: State<'_, Arc<AppState>>,
connection_id: String,
server: String,
catalog: String,
schema: String,
filter: Option<String>,
limit: Option<usize>,
offset: Option<usize>,
) -> Result<Vec<db::TableInfo>, String> {
dbx_core::schema::list_sqlserver_linked_server_tables_core(
&state,
&connection_id,
&server,
&catalog,
&schema,
filter.as_deref(),
limit,
offset,
)
.await
}
#[tauri::command]
pub async fn list_schemas(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
apply_visible_filter: Option<bool>,
) -> Result<Vec<String>, String> {
dbx_core::schema::list_schemas_core_with_visible_filter(
&state,
&connection_id,
&database,
apply_visible_filter.unwrap_or(false),
)
.await
}
#[tauri::command]
pub async fn list_schema_infos(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
) -> Result<Vec<db::SchemaInfo>, String> {
dbx_core::schema::list_schema_infos_core(&state, &connection_id, &database).await
}
#[tauri::command]
pub async fn list_data_types(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
) -> Result<Vec<String>, String> {
dbx_core::schema::list_data_types_core(&state, &connection_id, &database).await
}
#[tauri::command]
pub async fn list_tables(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
filter: Option<String>,
limit: Option<usize>,
offset: Option<usize>,
object_types: Option<Vec<String>>,
catalog: Option<String>,
table_name_filter: Option<dbx_core::schema::TableNameFilter>,
) -> Result<Vec<db::TableInfo>, String> {
if let Some(catalog) = external_doris_catalog(&state, &connection_id, catalog.as_deref()).await {
return dbx_core::schema::list_doris_catalog_tables_core(
&state,
&connection_id,
&catalog,
&database,
filter.as_deref(),
limit,
offset,
object_types.as_deref(),
table_name_filter.as_ref(),
)
.await;
}
dbx_core::schema::list_tables_core(
&state,
&connection_id,
&database,
&schema,
filter.as_deref(),
limit,
offset,
object_types.as_deref(),
table_name_filter.as_ref(),
)
.await
}
#[tauri::command]
pub async fn get_table_comment(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
catalog: Option<String>,
) -> Result<Option<String>, String> {
if let Some(catalog) = external_doris_catalog(&state, &connection_id, catalog.as_deref()).await {
return dbx_core::schema::get_doris_catalog_table_comment_core(
&state,
&connection_id,
&catalog,
&database,
&table,
)
.await;
}
dbx_core::schema::get_table_comment_core(&state, &connection_id, &database, &schema, &table).await
}
#[tauri::command]
pub async fn get_mysql_table_auto_increment(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
table: String,
) -> Result<Option<String>, String> {
dbx_core::schema::get_mysql_table_auto_increment_core(&state, &connection_id, &database, &table).await
}
#[tauri::command]
pub async fn list_objects(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
filter: Option<String>,
limit: Option<usize>,
offset: Option<usize>,
object_types: Option<Vec<String>>,
catalog: Option<String>,
table_name_filter: Option<dbx_core::schema::TableNameFilter>,
) -> Result<Vec<db::ObjectInfo>, String> {
if let Some(catalog) = external_doris_catalog(&state, &connection_id, catalog.as_deref()).await {
let tables = dbx_core::schema::list_doris_catalog_tables_core(
&state,
&connection_id,
&catalog,
&database,
filter.as_deref(),
limit,
offset,
object_types.as_deref(),
table_name_filter.as_ref(),
)
.await?;
return Ok(tables
.into_iter()
.map(|table| db::ObjectInfo {
name: table.name,
object_type: table.table_type,
schema: Some(database.clone()),
valid: None,
signature: None,
comment: table.comment,
created_at: None,
updated_at: None,
parent_schema: table.parent_schema,
parent_name: table.parent_name,
custom_type_kind: None,
has_members: None,
trigger: None,
xugu_type_members_expandable: None,
})
.collect());
}
dbx_core::schema::list_objects_core(
&state,
&connection_id,
&database,
&schema,
filter.as_deref(),
limit,
offset,
object_types.as_deref(),
table_name_filter.as_ref(),
)
.await
}
#[tauri::command]
pub async fn list_object_statistics(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
) -> Result<Vec<db::ObjectStatistics>, String> {
dbx_core::schema::list_object_statistics_core(&state, &connection_id, &database, &schema).await
}
#[tauri::command]
pub async fn list_completion_objects(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
) -> Result<Vec<db::ObjectInfo>, String> {
dbx_core::schema::list_completion_objects_core(&state, &connection_id, &database, &schema).await
}
#[tauri::command]
pub async fn completion_assistant_search(
state: State<'_, Arc<AppState>>,
request: db::CompletionAssistantRequest,
) -> Result<db::CompletionAssistantResponse, String> {
dbx_core::schema::completion_assistant_search_core(&state, request).await
}
#[tauri::command]
pub async fn get_object_source(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
name: String,
object_type: db::ObjectSourceKind,
signature: Option<String>,
relation_name: Option<String>,
) -> Result<db::ObjectSource, String> {
dbx_core::schema::get_object_source_core(
&state,
&connection_id,
&database,
&schema,
&name,
object_type,
signature.as_deref(),
relation_name.as_deref(),
)
.await
}
#[tauri::command]
pub async fn get_event_info(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
name: String,
) -> Result<db::MysqlEventInfo, String> {
dbx_core::schema::get_event_info_core(&state, &connection_id, &database, &schema, &name).await
}
#[tauri::command]
pub async fn get_custom_type_details(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
name: String,
) -> Result<db::CustomTypeDetails, String> {
dbx_core::schema::get_custom_type_details_core(&state, &connection_id, &database, &schema, &name).await
}
#[tauri::command]
pub async fn get_columns(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
catalog: Option<String>,
client_session_id: Option<String>,
) -> Result<Vec<db::ColumnInfo>, String> {
if let Some(catalog) = external_doris_catalog(&state, &connection_id, catalog.as_deref()).await {
return dbx_core::schema::get_doris_catalog_columns_core(&state, &connection_id, &catalog, &database, &table)
.await;
}
dbx_core::schema::get_columns_core_for_session(
&state,
&connection_id,
&database,
&schema,
&table,
client_session_id.as_deref(),
)
.await
}
/// Read-only Plugin Host API over the existing connection. The core function
/// performs the open-connection gate before entering the ordinary metadata path.
#[tauri::command]
pub async fn get_plugin_table_metadata(
state: State<'_, Arc<AppState>>,
request: dbx_core::schema::plugin_metadata::PluginTableContext,
) -> Result<dbx_core::schema::plugin_metadata::PluginTableMetadata, String> {
dbx_core::schema::plugin_metadata::get_table_metadata(&state, request).await
}
#[tauri::command]
pub async fn get_all_columns(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
) -> Result<Vec<db::TableColumnsResult>, String> {
dbx_core::schema::get_all_columns_core(&state, &connection_id, &database, &schema).await
}
#[tauri::command]
pub async fn get_sqlserver_column_metadata(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
) -> Result<Vec<db::sqlserver::SqlServerColumnMetadata>, String> {
dbx_core::schema::get_sqlserver_column_metadata_core(&state, &connection_id, &database, &schema, &table).await
}
#[tauri::command]
pub async fn list_indexes(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
catalog: Option<String>,
) -> Result<Vec<db::IndexInfo>, String> {
if let Some(catalog) = external_doris_catalog(&state, &connection_id, catalog.as_deref()).await {
return dbx_core::schema::list_doris_catalog_indexes_core(&state, &connection_id, &catalog, &database, &table)
.await;
}
dbx_core::schema::list_indexes_core(&state, &connection_id, &database, &schema, &table).await
}
#[tauri::command]
pub async fn list_reference_key_columns(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
catalog: Option<String>,
) -> Result<Vec<String>, String> {
if let Some(catalog) = external_doris_catalog(&state, &connection_id, catalog.as_deref()).await {
let indexes =
dbx_core::schema::list_doris_catalog_indexes_core(&state, &connection_id, &catalog, &database, &table)
.await?;
return Ok(dbx_core::schema::reference_key_columns_from_indexes(&indexes));
}
dbx_core::schema::list_reference_key_columns_core(&state, &connection_id, &database, &schema, &table).await
}
#[tauri::command]
pub async fn list_reference_keys(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
catalog: Option<String>,
) -> Result<Vec<dbx_core::schema::ReferenceKeyInfo>, String> {
if let Some(catalog) = external_doris_catalog(&state, &connection_id, catalog.as_deref()).await {
let indexes =
dbx_core::schema::list_doris_catalog_indexes_core(&state, &connection_id, &catalog, &database, &table)
.await?;
return Ok(dbx_core::schema::reference_keys_from_indexes(&indexes));
}
dbx_core::schema::list_reference_keys_core(&state, &connection_id, &database, &schema, &table).await
}
#[tauri::command]
pub async fn list_foreign_keys(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
catalog: Option<String>,
) -> Result<Vec<db::ForeignKeyInfo>, String> {
if let Some(catalog) = external_doris_catalog(&state, &connection_id, catalog.as_deref()).await {
return dbx_core::schema::list_doris_catalog_foreign_keys_core(
&state,
&connection_id,
&catalog,
&database,
&table,
)
.await;
}
dbx_core::schema::list_foreign_keys_core(&state, &connection_id, &database, &schema, &table).await
}
#[tauri::command]
pub async fn list_triggers(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
catalog: Option<String>,
) -> Result<Vec<db::TriggerInfo>, String> {
if let Some(catalog) = external_doris_catalog(&state, &connection_id, catalog.as_deref()).await {
return dbx_core::schema::list_doris_catalog_triggers_core(&state, &connection_id, &catalog, &database, &table)
.await;
}
dbx_core::schema::list_triggers_core(&state, &connection_id, &database, &schema, &table).await
}
#[tauri::command]
pub async fn list_constraints(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
catalog: Option<String>,
) -> Result<Vec<dbx_core::db::ConstraintInfo>, String> {
let _ = catalog;
dbx_core::schema::list_constraints_core(&state, &connection_id, &database, &schema, &table).await
}
#[tauri::command]
pub async fn list_partitions(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
) -> Result<Vec<dbx_core::db::PartitionInfo>, String> {
dbx_core::schema::list_partitions_core(&state, &connection_id, &database, &schema, &table).await
}
#[tauri::command]
pub async fn get_table_partition_status(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
) -> Result<dbx_core::schema::TablePartitionStatus, String> {
dbx_core::schema::table_partition_status_core(&state, &connection_id, &database, &schema, &table).await
}
#[tauri::command]
pub async fn list_invalid_indexes(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
) -> Result<Vec<String>, String> {
dbx_core::schema::list_invalid_indexes_core(&state, &connection_id, &database, &schema, &table).await
}
#[tauri::command]
pub async fn get_table_partitioning(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
) -> Result<dbx_core::db::PgTablePartitioning, String> {
dbx_core::schema::get_table_partitioning_core(&state, &connection_id, &database, &schema, &table).await
}
#[tauri::command]
pub async fn list_subpartitions(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
) -> Result<Vec<dbx_core::db::SubpartitionInfo>, String> {
dbx_core::schema::list_subpartitions_core(&state, &connection_id, &database, &schema, &table).await
}
#[tauri::command]
pub async fn get_table_ddl(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
object_type: Option<db::ObjectSourceKind>,
catalog: Option<String>,
include_postgres_access: Option<bool>,
portable: Option<bool>,
) -> Result<String, String> {
if let Some(catalog) = external_doris_catalog(&state, &connection_id, catalog.as_deref()).await {
return dbx_core::schema::get_doris_catalog_table_ddl_core(&state, &connection_id, &catalog, &database, &table)
.await;
}
if portable.unwrap_or(false) {
dbx_core::schema::get_table_export_ddl_core(&state, &connection_id, &database, &schema, &table, object_type)
.await
} else if include_postgres_access.unwrap_or(false) {
dbx_core::schema::get_table_display_ddl_core(&state, &connection_id, &database, &schema, &table, object_type)
.await
} else {
dbx_core::schema::get_table_ddl_core(&state, &connection_id, &database, &schema, &table, object_type).await
}
}
#[tauri::command]
pub async fn list_functions(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
) -> Result<Vec<db::FunctionInfo>, String> {
dbx_core::schema::list_functions_core(&state, &connection_id, &database, &schema).await
}
#[tauri::command]
pub async fn list_sequences(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
with_last_values: bool,
) -> Result<Vec<db::SequenceInfo>, String> {
dbx_core::schema::list_sequences_core(&state, &connection_id, &database, &schema, with_last_values).await
}
#[tauri::command]
pub async fn list_rules(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
) -> Result<Vec<db::RuleInfo>, String> {
dbx_core::schema::list_rules_core(&state, &connection_id, &database, &schema).await
}
#[tauri::command]
pub async fn list_owners(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
) -> Result<Vec<db::OwnerInfo>, String> {
dbx_core::schema::list_owners_core(&state, &connection_id, &database, &schema).await
}
#[tauri::command]
pub async fn get_table_owner(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: String,
table: String,
) -> Result<Option<String>, String> {
dbx_core::schema::get_table_owner_core(&state, &connection_id, &database, &schema, &table).await
}
#[tauri::command]
pub async fn list_extensions(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
schema: Option<String>,
) -> Result<Vec<db::ExtensionInfo>, String> {
dbx_core::schema::list_extensions_core(&state, &connection_id, &database, schema.as_deref()).await
}
#[tauri::command]
pub async fn list_available_extensions(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
) -> Result<Vec<db::ExtensionInfo>, String> {
dbx_core::schema::list_available_extensions_core(&state, &connection_id, &database).await
}
#[tauri::command]
pub async fn list_event_triggers(
state: State<'_, Arc<AppState>>,
connection_id: String,
database: String,
) -> Result<Vec<db::EventTriggerInfo>, String> {
dbx_core::schema::list_event_triggers_core(&state, &connection_id, &database).await
}
+93
View File
@@ -0,0 +1,93 @@
mod commands;
macro_rules! define_registry {
($($command:ident),+ $(,)?) => {
const COMMANDS: &[&str] = &[$(stringify!($command)),+];
pub fn invoke_handler() -> impl Fn(tauri::ipc::Invoke<tauri::Wry>) -> bool + Send + Sync + 'static {
tauri::generate_handler![$(commands::$command),+]
}
};
}
define_registry![
list_databases,
list_database_metadata,
list_database_storage,
list_xugu_tablespaces,
get_sqlserver_completion_context,
list_doris_catalogs,
list_doris_catalog_databases,
list_sqlserver_linked_servers,
list_sqlserver_linked_server_catalogs,
list_sqlserver_linked_server_schemas,
list_sqlserver_linked_server_tables,
list_tables,
get_table_comment,
get_mysql_table_auto_increment,
list_objects,
list_object_statistics,
list_completion_objects,
completion_assistant_search,
get_object_source,
get_event_info,
get_custom_type_details,
list_schemas,
list_schema_infos,
list_data_types,
get_columns,
get_plugin_table_metadata,
get_all_columns,
get_sqlserver_column_metadata,
list_indexes,
list_reference_key_columns,
list_reference_keys,
list_foreign_keys,
list_triggers,
list_constraints,
list_partitions,
get_table_partition_status,
get_table_partitioning,
list_invalid_indexes,
list_subpartitions,
get_table_ddl,
list_functions,
list_sequences,
list_rules,
list_owners,
get_table_owner,
list_extensions,
list_available_extensions,
list_event_triggers,
];
pub fn handles(command: &str) -> bool {
COMMANDS.contains(&command)
}
pub fn route(
main_handler: impl Fn(tauri::ipc::Invoke<tauri::Wry>) -> bool + Send + Sync + 'static,
) -> impl Fn(tauri::ipc::Invoke<tauri::Wry>) -> bool + Send + Sync + 'static {
let schema_handler = invoke_handler();
move |invoke| {
if handles(invoke.message.command()) {
schema_handler(invoke)
} else {
main_handler(invoke)
}
}
}
#[cfg(test)]
mod tests {
use super::{handles, COMMANDS};
#[test]
fn handles_only_schema_commands() {
assert_eq!(COMMANDS.len(), 48);
assert!(handles("list_databases"));
assert!(handles("list_event_triggers"));
assert!(!handles("prepare_schema_diff"));
assert!(!handles("load_connections"));
}
}