Skip to content

armgit / dbx

Public Imported from GitHub
0

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。

4.0 KB
Raw Blame
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,
    native_job_open_context,
    native_job_list,
    native_job_references,
    native_job_read,
    native_job_prepare,
    native_job_apply,
    native_job_status,
    native_job_cancel,
    get_oracle_type_management_snapshot,
    build_oracle_type_management_sql,
    verify_oracle_type_data,
    prepare_oracle_type_evolution,
    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_foreign_keys_for_database,
    list_triggers,
    list_constraints,
    list_partitions,
    get_table_partition_status,
    get_table_partitioning,
    list_invalid_indexes,
    list_subpartitions,
    get_table_ddl,
    list_functions,
    load_schema_diff_routines,
    prepare_oracle_routine_save,
    prepare_oracle_routine_plan,
    prepare_oracle_routine_recovery,
    execute_oracle_routine_operation,
    observe_oracle_routine_operation,
    update_oracle_routine_operation_references,
    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_including_native_jobs() {
        assert_eq!(COMMANDS.len(), 68);
        assert!(handles("list_databases"));
        assert!(handles("load_schema_diff_routines"));
        assert!(handles("prepare_oracle_routine_save"));
        assert!(handles("prepare_oracle_routine_plan"));
        assert!(handles("prepare_oracle_routine_recovery"));
        assert!(handles("execute_oracle_routine_operation"));
        assert!(handles("observe_oracle_routine_operation"));
        assert!(handles("update_oracle_routine_operation_references"));
        assert!(handles("list_event_triggers"));
        for command in [
            "native_job_open_context",
            "native_job_list",
            "native_job_references",
            "native_job_read",
            "native_job_prepare",
            "native_job_apply",
            "native_job_status",
            "native_job_cancel",
            "get_oracle_type_management_snapshot",
            "build_oracle_type_management_sql",
            "verify_oracle_type_data",
            "prepare_oracle_type_evolution",
        ] {
            assert!(handles(command), "{command}");
        }
        assert!(!handles("prepare_schema_diff"));
        assert!(!handles("load_connections"));
    }
}