45 lines
1.7 KiB
Rust
45 lines
1.7 KiB
Rust
// file: kb-app-demo-desktop/src/demo_sql_pg_core.rs
|
|
// version: 6
|
|
|
|
//! PostgreSQL core store demo commands.
|
|
|
|
use ts_rs::TS; // rust-rules: derive-import
|
|
|
|
/// PostgreSQL core store payload shown by `demo_sql_pg_core`.
|
|
#[derive(Clone, Debug, serde::Serialize, TS)]
|
|
#[serde(rename_all = "camelCase")]
|
|
#[ts(
|
|
export,
|
|
export_to = "../frontend/ts/bindings/kb_app_demo_desktop/demo_sql_pg_core/DemoSqlPgCorePayload.ts"
|
|
)]
|
|
pub(crate) struct DemoSqlPgCorePayload {
|
|
/// Active profile name.
|
|
pub(crate) active_profile_name: std::string::String,
|
|
/// Masked PostgreSQL DSN.
|
|
pub(crate) masked_dsn: std::string::String,
|
|
/// Core table diagnostics.
|
|
pub(crate) tables: std::vec::Vec<crate::DemoSqlTableSnapshot>,
|
|
}
|
|
|
|
/// Loads read-only core table diagnostics from PostgreSQL.
|
|
pub(crate) async fn load_demo_sql_pg_core(
|
|
state: tauri::State<'_, crate::AppState>,
|
|
) -> std::result::Result<crate::DemoSqlPgCorePayload, std::string::String> {
|
|
let profile = state.active_profile().clone();
|
|
let store_result = crate::connect_postgres_store(&profile).await;
|
|
let store = match store_result {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
};
|
|
let tables_result = store.core_table_diagnostics().await;
|
|
let tables = match tables_result {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error.to_string()),
|
|
};
|
|
return std::result::Result::Ok(crate::DemoSqlPgCorePayload {
|
|
active_profile_name: profile.name.clone(),
|
|
masked_dsn: store.options().masked_dsn(),
|
|
tables: crate::table_snapshots_from_pg(tables.as_slice()),
|
|
});
|
|
}
|