daoyi_cloud_common/config/db_config.rs
1use serde::{Deserialize, Serialize};
2
3use super::default_false;
4
5#[derive(Deserialize, Serialize, Clone, Debug)]
6pub struct DbConfig {
7 /// Settings for the primary database. This is usually writeable, but will be read-only in
8 /// some configurations.
9 /// An optional follower database. Always read-only.
10 #[serde(alias = "database_url")]
11 pub url: String,
12 #[serde(default = "default_db_pool_size")]
13 pub pool_size: u32,
14 pub min_idle: Option<u32>,
15
16 /// Number of seconds to wait for unacknowledged TCP packets before treating the connection as
17 /// broken. This value will determine how long crates.io stays unavailable in case of full
18 /// packet loss between the application and the database: setting it too high will result in an
19 /// unnecessarily long outage (before the unhealthy database logic kicks in), while setting it
20 /// too low might result in healthy connections being dropped.
21 #[serde(default = "default_tcp_timeout")]
22 pub tcp_timeout: u64,
23 /// Time to wait for a connection to become available from the connection
24 /// pool before returning an error.
25 /// Time to wait for a connection to become available from the connection
26 /// pool before returning an error.
27 #[serde(default = "default_connection_timeout")]
28 pub connection_timeout: u64,
29 /// Time to wait for a query response before canceling the query and
30 /// returning an error.
31 #[serde(default = "default_statement_timeout")]
32 pub statement_timeout: u64,
33 /// Number of threads to use for asynchronous operations such as connection
34 /// creation.
35 #[serde(default = "default_helper_threads")]
36 pub helper_threads: usize,
37 /// Whether to enforce that all the database connections are encrypted with TLS.
38 #[serde(default = "default_false")]
39 pub enforce_tls: bool,
40}
41
42fn default_helper_threads() -> usize {
43 10
44}
45fn default_db_pool_size() -> u32 {
46 10
47}
48fn default_tcp_timeout() -> u64 {
49 10000
50}
51fn default_connection_timeout() -> u64 {
52 30000
53}
54fn default_statement_timeout() -> u64 {
55 30000
56}