spin_trigger/cli/
summary.rsuse spin_core::async_trait;
use spin_factor_key_value::KeyValueFactor;
use spin_factor_sqlite::SqliteFactor;
use spin_factors::RuntimeFactors;
use spin_factors_executor::ExecutorHooks;
pub struct KeyValueDefaultStoreSummaryHook;
#[async_trait]
impl<F: RuntimeFactors, U> ExecutorHooks<F, U> for KeyValueDefaultStoreSummaryHook {
async fn configure_app(
&self,
configured_app: &spin_factors::ConfiguredApp<F>,
) -> anyhow::Result<()> {
let Ok(kv_app_state) = configured_app.app_state::<KeyValueFactor>() else {
return Ok(());
};
if !kv_app_state.store_is_used("default") {
return Ok(());
}
if let Some(default_store_summary) = kv_app_state.store_summary("default") {
println!("Storing default key-value data to {default_store_summary}.");
}
Ok(())
}
}
pub struct SqliteDefaultStoreSummaryHook;
#[async_trait]
impl<F: RuntimeFactors, U> ExecutorHooks<F, U> for SqliteDefaultStoreSummaryHook {
async fn configure_app(
&self,
configured_app: &spin_factors::ConfiguredApp<F>,
) -> anyhow::Result<()> {
let Ok(sqlite_app_state) = configured_app.app_state::<SqliteFactor>() else {
return Ok(());
};
if !sqlite_app_state.database_is_used("default") {
return Ok(());
}
if let Some(default_database_summary) = sqlite_app_state
.get_connection("default")
.await
.and_then(Result::ok)
.and_then(|conn| conn.summary())
{
println!("Storing default SQLite data to {default_database_summary}.");
}
Ok(())
}
}