spring_sqlx/config.rs
1use schemars::JsonSchema;
2use serde::Deserialize;
3use spring::config::Configurable;
4
5spring::submit_config_schema!("sqlx", SqlxConfig);
6
7#[derive(Debug, Configurable, Clone, JsonSchema, Deserialize)]
8#[config_prefix = "sqlx"]
9#[allow(clippy::struct_excessive_bools)]
10pub struct SqlxConfig {
11 /// The URI for connecting to the database. For example:
12 /// * Postgres: `postgres://root:12341234@localhost:5432/myapp_development`
13 /// * Sqlite: `sqlite://db.sqlite?mode=rwc`
14 pub uri: String,
15
16 /// Minimum number of connections for a pool
17 #[serde(default = "default_min_connections")]
18 pub min_connections: u32,
19
20 /// Maximum number of connections for a pool
21 #[serde(default = "default_max_connections")]
22 pub max_connections: u32,
23
24 /// Set the timeout duration when acquiring a connection
25 pub connect_timeout: Option<u64>,
26
27 /// Set a maximum idle duration for individual connections.
28 /// Any connection that remains in the idle queue longer than this will be closed.
29 /// For usage-based database server billing, this can be a cost saver.
30 pub idle_timeout: Option<u64>,
31
32 /// Set the timeout for acquiring a connection
33 pub acquire_timeout: Option<u64>,
34}
35
36fn default_min_connections() -> u32 {
37 1
38}
39
40fn default_max_connections() -> u32 {
41 10
42}