diff --git a/src/database.rs b/src/database.rs index b894273..543217a 100644 --- a/src/database.rs +++ b/src/database.rs @@ -1,13 +1,18 @@ use anyhow::Result; use migration::{Migrator, MigratorTrait}; -use sea_orm::{Database, DatabaseConnection}; +use sea_orm::{ConnectOptions, Database, DatabaseConnection}; use tokio::fs; use crate::config::CONFIG_DIR; pub async fn database_connection() -> Result { let target = CONFIG_DIR.join("data.sqlite"); fs::create_dir_all(&*CONFIG_DIR).await?; - Ok(Database::connect(format!("sqlite://{}?mode=rwc", target.to_str().unwrap())).await?) + let mut option = ConnectOptions::new(format!("sqlite://{}?mode=rwc", target.to_str().unwrap())); + option + .max_connections(100) + .min_connections(5) + .acquire_timeout(std::time::Duration::from_secs(90)); + Ok(Database::connect(option).await?) } pub async fn migrate_database(connection: &DatabaseConnection) -> Result<()> {