Skip to main content

spin_factor_outbound_mysql/runtime_config/
spin.rs

1use serde::Deserialize;
2use spin_factors::runtime_config::toml::GetTomlValue;
3
4/// Get the runtime configuration for outbound MySQL from a TOML table.
5///
6/// Expects table to be in the format:
7/// ```toml
8/// [outbound_mysql]
9/// max_connections = 10 # optional, defaults to unlimited
10/// ```
11pub fn config_from_table(
12    table: &impl GetTomlValue,
13) -> anyhow::Result<Option<super::RuntimeConfig>> {
14    if let Some(outbound_mysql) = table.get("outbound_mysql") {
15        let toml = outbound_mysql.clone().try_into::<OutboundMysqlToml>()?;
16        Ok(Some(super::RuntimeConfig {
17            max_connections: toml.max_connections,
18            wait_timeout: None,
19        }))
20    } else {
21        Ok(None)
22    }
23}
24
25#[derive(Debug, Default, Deserialize)]
26#[serde(deny_unknown_fields)]
27struct OutboundMysqlToml {
28    #[serde(default)]
29    max_connections: Option<usize>,
30}