use std::sync::Arc; use tauri::State; use crate::commands::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 { dbx_core::schema::resolve_external_doris_catalog(state, connection_id, catalog).await } #[tauri::command] pub async fn list_databases( state: State<'_, Arc>, connection_id: String, ) -> Result, String> { dbx_core::schema::list_databases_core(&state, &connection_id).await } #[tauri::command] pub async fn list_database_metadata( state: State<'_, Arc>, connection_id: String, ) -> Result, String> { dbx_core::schema::list_database_metadata_core(&state, &connection_id).await } #[tauri::command] pub async fn list_database_storage( state: State<'_, Arc>, connection_id: String, databases: Vec, ) -> Result, String> { dbx_core::schema::list_database_storage_core(&state, &connection_id, &databases).await } #[tauri::command] pub async fn get_sqlserver_completion_context( state: State<'_, Arc>, connection_id: String, database: String, ) -> Result { dbx_core::schema::get_sqlserver_completion_context_core(&state, &connection_id, &database).await } #[tauri::command] pub async fn list_doris_catalogs( state: State<'_, Arc>, connection_id: String, ) -> Result, String> { dbx_core::schema::list_doris_catalogs_core(&state, &connection_id).await } #[tauri::command] pub async fn list_doris_catalog_databases( state: State<'_, Arc>, connection_id: String, catalog: String, ) -> Result, 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>, connection_id: String, ) -> Result, 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>, connection_id: String, server: String, ) -> Result, 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>, connection_id: String, server: String, catalog: String, ) -> Result, 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>, connection_id: String, server: String, catalog: String, schema: String, filter: Option, limit: Option, offset: Option, ) -> Result, 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>, connection_id: String, database: String, apply_visible_filter: Option, ) -> Result, 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>, connection_id: String, database: String, ) -> Result, String> { dbx_core::schema::list_schema_infos_core(&state, &connection_id, &database).await } #[tauri::command] pub async fn list_data_types( state: State<'_, Arc>, connection_id: String, database: String, ) -> Result, String> { dbx_core::schema::list_data_types_core(&state, &connection_id, &database).await } #[tauri::command] pub async fn list_tables( state: State<'_, Arc>, connection_id: String, database: String, schema: String, filter: Option, limit: Option, offset: Option, object_types: Option>, catalog: Option, table_name_filter: Option, ) -> Result, 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>, connection_id: String, database: String, schema: String, table: String, catalog: Option, ) -> Result, 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 list_objects( state: State<'_, Arc>, connection_id: String, database: String, schema: String, filter: Option, limit: Option, offset: Option, object_types: Option>, catalog: Option, ) -> Result, 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(), None, ) .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(), ) .await } #[tauri::command] pub async fn list_object_statistics( state: State<'_, Arc>, connection_id: String, database: String, schema: String, ) -> Result, 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>, connection_id: String, database: String, schema: String, ) -> Result, 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>, request: db::CompletionAssistantRequest, ) -> Result { dbx_core::schema::completion_assistant_search_core(&state, request).await } #[tauri::command] pub async fn get_object_source( state: State<'_, Arc>, connection_id: String, database: String, schema: String, name: String, object_type: db::ObjectSourceKind, signature: Option, relation_name: Option, ) -> Result { 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_custom_type_details( state: State<'_, Arc>, connection_id: String, database: String, schema: String, name: String, ) -> Result { 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>, connection_id: String, database: String, schema: String, table: String, catalog: Option, client_session_id: Option, ) -> Result, 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 } #[tauri::command] pub async fn get_all_columns( state: State<'_, Arc>, connection_id: String, database: String, schema: String, ) -> Result, 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>, connection_id: String, database: String, schema: String, table: String, ) -> Result, 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>, connection_id: String, database: String, schema: String, table: String, catalog: Option, ) -> Result, 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_foreign_keys( state: State<'_, Arc>, connection_id: String, database: String, schema: String, table: String, catalog: Option, ) -> Result, 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>, connection_id: String, database: String, schema: String, table: String, catalog: Option, ) -> Result, 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>, connection_id: String, database: String, schema: String, table: String, ) -> Result, String> { dbx_core::schema::list_constraints_core(&state, &connection_id, &database, &schema, &table).await } #[tauri::command] pub async fn list_partitions( state: State<'_, Arc>, connection_id: String, database: String, schema: String, table: String, ) -> Result, String> { dbx_core::schema::list_partitions_core(&state, &connection_id, &database, &schema, &table).await } #[tauri::command] pub async fn list_subpartitions( state: State<'_, Arc>, connection_id: String, database: String, schema: String, table: String, ) -> Result, 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>, connection_id: String, database: String, schema: String, table: String, object_type: Option, catalog: Option, include_postgres_access: Option, ) -> Result { 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 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>, connection_id: String, database: String, schema: String, ) -> Result, String> { dbx_core::schema::list_functions_core(&state, &connection_id, &database, &schema).await } #[tauri::command] pub async fn list_sequences( state: State<'_, Arc>, connection_id: String, database: String, schema: String, with_last_values: bool, ) -> Result, 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>, connection_id: String, database: String, schema: String, ) -> Result, String> { dbx_core::schema::list_rules_core(&state, &connection_id, &database, &schema).await } #[tauri::command] pub async fn list_owners( state: State<'_, Arc>, connection_id: String, database: String, schema: String, ) -> Result, String> { dbx_core::schema::list_owners_core(&state, &connection_id, &database, &schema).await } #[tauri::command] pub async fn list_extensions( state: State<'_, Arc>, connection_id: String, database: String, schema: Option, ) -> Result, 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>, connection_id: String, database: String, ) -> Result, String> { dbx_core::schema::list_available_extensions_core(&state, &connection_id, &database).await }