11use spin_core:: async_trait;
22use spin_factor_key_value:: KeyValueFactor ;
3+ use spin_factor_sqlite:: SqliteFactor ;
34use spin_factors_executor:: ExecutorHooks ;
45
56use crate :: factors:: TriggerFactors ;
67
8+ /// An [`ExecutorHooks`] that prints information about the default KV store.
79pub struct KeyValueDefaultStoreSummaryHook ;
810
911#[ async_trait]
@@ -12,13 +14,43 @@ impl<U> ExecutorHooks<TriggerFactors, U> for KeyValueDefaultStoreSummaryHook {
1214 & mut self ,
1315 configured_app : & spin_factors:: ConfiguredApp < TriggerFactors > ,
1416 ) -> anyhow:: Result < ( ) > {
15- if let Some ( default_store_summary) = configured_app
16- . app_state :: < KeyValueFactor > ( )
17- . ok ( )
18- . and_then ( |kv_state| kv_state. store_summary ( "default" ) )
19- {
17+ let Ok ( kv_app_state) = configured_app. app_state :: < KeyValueFactor > ( ) else {
18+ return Ok ( ( ) ) ;
19+ } ;
20+ if !kv_app_state. store_is_used ( "default" ) {
21+ // We don't talk about unused default stores
22+ return Ok ( ( ) ) ;
23+ }
24+ if let Some ( default_store_summary) = kv_app_state. store_summary ( "default" ) {
2025 println ! ( "Storing default key-value data to {default_store_summary}." ) ;
2126 }
2227 Ok ( ( ) )
2328 }
2429}
30+
31+ /// An [`ExecutorHooks`] that prints information about the default KV store.
32+ pub struct SqliteDefaultStoreSummaryHook ;
33+
34+ #[ async_trait]
35+ impl < U > ExecutorHooks < TriggerFactors , U > for SqliteDefaultStoreSummaryHook {
36+ async fn configure_app (
37+ & mut self ,
38+ configured_app : & spin_factors:: ConfiguredApp < TriggerFactors > ,
39+ ) -> anyhow:: Result < ( ) > {
40+ let Ok ( sqlite_app_state) = configured_app. app_state :: < SqliteFactor > ( ) else {
41+ return Ok ( ( ) ) ;
42+ } ;
43+ if !sqlite_app_state. database_is_used ( "default" ) {
44+ // We don't talk about unused default databases
45+ return Ok ( ( ) ) ;
46+ }
47+ if let Some ( default_database_summary) = sqlite_app_state
48+ . get_connection ( "default" )
49+ . and_then ( Result :: ok)
50+ . and_then ( |conn| conn. summary ( ) )
51+ {
52+ println ! ( "Storing default SQLite data to {default_database_summary}." ) ;
53+ }
54+ Ok ( ( ) )
55+ }
56+ }
0 commit comments