Skip to content

Commit

Permalink
feat: 放宽数据库连接池的连接数和获取时间,避免 time out 错误 (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoaer committed Apr 29, 2024
1 parent f81d9fc commit e732e7d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/database.rs
Original file line number Diff line number Diff line change
@@ -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<DatabaseConnection> {
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<()> {
Expand Down

0 comments on commit e732e7d

Please sign in to comment.