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