Struct rocket_sync_db_pools::Config [−][src]
Expand description
A base Config
for any Poolable
type.
For the following configuration:
[global.databases.my_database]
url = "postgres://root:root@localhost/my_database"
pool_size = 10
timeout = 5
…Config::from("my_database", rocket)
would return the following struct:
Config { url: "postgres://root:root@localhost/my_database".into(), pool_size: 10, timeout: 5 };
If you want to implement your own custom database adapter (or other
database-like struct that can be pooled by r2d2
) and need some more
configurations options, you may need to define a custom Config
struct.
Note, however, that the configuration values in Config
are required.
Fields
url: String
Connection URL specified in the Rocket configuration.
pool_size: u32
Initial pool size. Defaults to the number of Rocket workers * 4.
timeout: u8
How long to wait, in seconds, for a new connection before timing out.
Defaults to 5
.
Implementations
Retrieves the database configuration for the database named name
.
This function is primarily used by the generated code from the
#[database]
attribute.
Example
// Assume that these are the contents of `Rocket.toml`: [default.databases] my_db = { url = "db/db.sqlite", pool_size = 25 } my_other_db = { url = "mysql://root:root@localhost/database" } use rocket::{Rocket, Build}; use rocket_sync_db_pools::Config; fn pool(rocket: &Rocket<Build>) { let config = Config::from("my_db", rocket).unwrap(); assert_eq!(config.url, "db/db.sqlite"); assert_eq!(config.pool_size, 25); let config = Config::from("my_other_db", rocket).unwrap(); assert_eq!(config.url, "mysql://root:root@localhost/database"); let workers = rocket.figment().extract_inner::<u32>(rocket::Config::WORKERS); assert_eq!(config.pool_size, (workers.unwrap() * 4)); let config = Config::from("unknown_db", rocket); assert!(config.is_err()) }
Returns a Figment
focused on the configuration for the database with
name db_name
.
Example
use rocket::{Rocket, Build}; use rocket_sync_db_pools::Config; fn pool(rocket: &Rocket<Build>) { let my_db_figment = Config::figment("my_db", rocket); let mysql_prod_figment = Config::figment("mysql_prod", rocket); }
Trait Implementations
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl RefUnwindSafe for Config
impl UnwindSafe for Config
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
Converts self
into a collection.
Convert self
to an expression for Diesel’s query builder. Read more
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
[src]
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
[src]Convert &self
to an expression for Diesel’s query builder. Read more
type Output = T
type Output = T
Should always be Self
pub fn vzip(self) -> V