Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting an acquire timeout #546

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ pub struct Database {
/// Set the idle duration before closing a connection
pub idle_timeout: u64,

/// Set the timeout for acquiring a connection
pub acquire_timeout: Option<u64>,

/// Run migration up when application loads. It is recommended to turn it on
/// in development. In production keep it off, and explicitly migrate your
/// database every time you need.
Expand Down
4 changes: 4 additions & 0 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ pub async fn connect(config: &config::Database) -> Result<DbConn, sea_orm::DbErr
.idle_timeout(Duration::from_millis(config.idle_timeout))
.sqlx_logging(config.enable_logging);

if let Some(acquire_timeout) = config.acquire_timeout {
opt.acquire_timeout(Duration::from_millis(acquire_timeout));
}

Database::connect(opt).await
}

Expand Down
Loading