diff --git a/contrib/db_pools/lib/src/config.rs b/contrib/db_pools/lib/src/config.rs index fcbbc345b7..1d20ef3e54 100644 --- a/contrib/db_pools/lib/src/config.rs +++ b/contrib/db_pools/lib/src/config.rs @@ -15,11 +15,14 @@ use rocket::serde::{Deserialize, Serialize}; /// [default.databases.db_name] /// url = "/path/to/db.sqlite" /// -/// # only `url` is required. `Initializer` provides defaults for the rest. +/// # Only `url` is required. You do not need to configure these. /// min_connections = 64 /// max_connections = 1024 /// connect_timeout = 5 /// idle_timeout = 120 +/// +/// # this option is only supported by the `sqlx_sqlite` driver +/// extensions = ["memvfs", "rot13"] /// ``` /// /// Alternatively, a custom provider can be used. For example, a custom `Figment` @@ -36,6 +39,7 @@ use rocket::serde::{Deserialize, Serialize}; /// max_connections: 1024, /// connect_timeout: 3, /// idle_timeout: None, +/// extensions: None, /// })); /// /// rocket::custom(figment) @@ -45,7 +49,8 @@ use rocket::serde::{Deserialize, Serialize}; /// For general information on configuration in Rocket, see [`rocket::config`]. /// For higher-level details on configuring a database, see the [crate-level /// docs](crate#configuration). -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +// NOTE: Defaults provided by the figment created in the `Initializer` fairing. +#[derive(Default, Serialize, Deserialize, Debug, Clone, PartialEq)] #[serde(crate = "rocket::serde")] pub struct Config { /// Database-specific connection and configuration URL. @@ -80,4 +85,11 @@ pub struct Config { /// /// _Default:_ `None`. pub idle_timeout: Option, + /// A list of database extensions to load at run-time. + /// + /// **Note:** Only the `sqlx_sqlite` driver supports this option (for SQLite + /// extensions) at this time. All other drivers ignore this option. + /// + /// _Default:_ `None`. + pub extensions: Option>, } diff --git a/contrib/db_pools/lib/src/database.rs b/contrib/db_pools/lib/src/database.rs index 6eabdd7280..6f9ae40729 100644 --- a/contrib/db_pools/lib/src/database.rs +++ b/contrib/db_pools/lib/src/database.rs @@ -261,8 +261,8 @@ impl Fairing for Initializer { let figment = rocket.figment() .focus(&format!("databases.{}", D::NAME)) - .merge(Serialized::default("max_connections", workers * 4)) - .merge(Serialized::default("connect_timeout", 5)); + .join(Serialized::default("max_connections", workers * 4)) + .join(Serialized::default("connect_timeout", 5)); match ::init(&figment).await { Ok(pool) => Ok(rocket.manage(D::from(pool))), diff --git a/contrib/db_pools/lib/src/pool.rs b/contrib/db_pools/lib/src/pool.rs index 4e3ef35d92..371c2f7659 100644 --- a/contrib/db_pools/lib/src/pool.rs +++ b/contrib/db_pools/lib/src/pool.rs @@ -281,6 +281,12 @@ mod sqlx { *o = std::mem::take(o) .busy_timeout(Duration::from_secs(__config.connect_timeout)) .create_if_missing(true); + + if let Some(ref exts) = __config.extensions { + for ext in exts { + *o = std::mem::take(o).extension(ext.clone()); + } + } } }