sea_orm_rocket/
config.rs

1use rocket::serde::{Deserialize, Serialize};
2
3/// Base configuration for all database drivers.
4///
5/// A dictionary matching this structure is extracted from the active
6/// [`Figment`](crate::figment::Figment), scoped to `databases.name`, where
7/// `name` is the name of the database, by the
8/// [`Initializer`](crate::Initializer) fairing on ignition and used to
9/// configure the relevant database and database pool.
10///
11/// With the default provider, these parameters are typically configured in a
12/// `Rocket.toml` file:
13///
14/// ```toml
15/// [default.databases.db_name]
16/// url = "/path/to/db.sqlite"
17///
18/// # only `url` is required. `Initializer` provides defaults for the rest.
19/// min_connections = 64
20/// max_connections = 1024
21/// connect_timeout = 5
22/// idle_timeout = 120
23/// ```
24///
25/// Alternatively, a custom provider can be used. For example, a custom `Figment`
26/// with a global `databases.name` configuration:
27///
28/// ```rust
29/// # use rocket::launch;
30/// #[launch]
31/// fn rocket() -> _ {
32///     let figment = rocket::Config::figment().merge((
33///         "databases.name",
34///         sea_orm_rocket::Config {
35///             url: "db:specific@config&url".into(),
36///             min_connections: None,
37///             max_connections: 1024,
38///             connect_timeout: 3,
39///             idle_timeout: None,
40///             sqlx_logging: true,
41///         },
42///     ));
43///
44///     rocket::custom(figment)
45/// }
46/// ```
47///
48/// For general information on configuration in Rocket, see [`rocket::config`].
49/// For higher-level details on configuring a database, see the [crate-level
50/// docs](crate#configuration).
51#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
52#[serde(crate = "rocket::serde")]
53pub struct Config {
54    /// Database-specific connection and configuration URL.
55    ///
56    /// The format of the URL is database specific; consult your database's
57    /// documentation.
58    pub url: String,
59    /// Minimum number of connections to maintain in the pool.
60    ///
61    /// **Note:** `deadpool` drivers do not support and thus ignore this value.
62    ///
63    /// _Default:_ `None`.
64    pub min_connections: Option<u32>,
65    /// Maximum number of connections to maintain in the pool.
66    ///
67    /// _Default:_ `workers * 4`.
68    pub max_connections: usize,
69    /// Number of seconds to wait for a connection before timing out.
70    ///
71    /// If the timeout elapses before a connection can be made or retrieved from
72    /// a pool, an error is returned.
73    ///
74    /// _Default:_ `5`.
75    pub connect_timeout: u64,
76    /// Maximum number of seconds to keep a connection alive for.
77    ///
78    /// After a connection is established, it is maintained in a pool for
79    /// efficient connection retrieval. When an `idle_timeout` is set, that
80    /// connection will be closed after the timeout elapses. If an
81    /// `idle_timeout` is not specified, the behavior is driver specific but
82    /// typically defaults to keeping a connection active indefinitely.
83    ///
84    /// _Default:_ `None`.
85    pub idle_timeout: Option<u64>,
86
87    /// Enable SQLx statement logging (default true)
88    #[serde(default)]
89    pub sqlx_logging: bool,
90}