Struct sea_orm_rocket::Config

source ·
pub struct Config {
    pub url: String,
    pub min_connections: Option<u32>,
    pub max_connections: usize,
    pub connect_timeout: u64,
    pub idle_timeout: Option<u64>,
    pub sqlx_logging: bool,
}
Expand description

Base configuration for all database drivers.

A dictionary matching this structure is extracted from the active Figment, scoped to databases.name, where name is the name of the database, by the Initializer fairing on ignition and used to configure the relevant database and database pool.

With the default provider, these parameters are typically configured in a Rocket.toml file:

[default.databases.db_name]
url = "/path/to/db.sqlite"

min_connections = 64
max_connections = 1024
connect_timeout = 5
idle_timeout = 120

Alternatively, a custom provider can be used. For example, a custom Figment with a global databases.name configuration:

#[launch]
fn rocket() -> _ {
    let figment = rocket::Config::figment().merge((
        "databases.name",
        sea_orm_rocket::Config {
            url: "db:specific@config&url".into(),
            min_connections: None,
            max_connections: 1024,
            connect_timeout: 3,
            idle_timeout: None,
            sqlx_logging: true,
        },
    ));

    rocket::custom(figment)
}

For general information on configuration in Rocket, see rocket::config. For higher-level details on configuring a database, see the crate-level docs.

Fields

url: String

Database-specific connection and configuration URL.

The format of the URL is database specific; consult your database’s documentation.

min_connections: Option<u32>

Minimum number of connections to maintain in the pool.

Note: deadpool drivers do not support and thus ignore this value.

Default: None.

max_connections: usize

Maximum number of connections to maintain in the pool.

Default: workers * 4.

connect_timeout: u64

Number of seconds to wait for a connection before timing out.

If the timeout elapses before a connection can be made or retrieved from a pool, an error is returned.

Default: 5.

idle_timeout: Option<u64>

Maximum number of seconds to keep a connection alive for.

After a connection is established, it is maintained in a pool for efficient connection retrieval. When an idle_timeout is set, that connection will be closed after the timeout elapses. If an idle_timeout is not specified, the behavior is driver specific but typically defaults to keeping a connection active indefinitely.

Default: None.

sqlx_logging: bool

Enable SQLx statement logging (default true)

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts self into a collection.
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more