fix(handlers): add handlers
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
use crate::config::AppConfig;
|
||||
use sqlx::postgres::{PgPool, PgPoolOptions};
|
||||
use std::time::Duration;
|
||||
|
||||
/// 初始化数据库连接池
|
||||
pub async fn init_pool(database_url: &str) -> Result<PgPool, sqlx::Error> {
|
||||
pub async fn init_pool(config: &AppConfig) -> Result<PgPool, sqlx::Error> {
|
||||
PgPoolOptions::new()
|
||||
.max_connections(20) // 根据服务器规格调整,IAM服务通常并发高
|
||||
.min_connections(5)
|
||||
.max_connections(config.db_max_connections)
|
||||
.min_connections(config.db_min_connections)
|
||||
.acquire_timeout(Duration::from_secs(3)) // 获取连接超时时间
|
||||
.connect(database_url)
|
||||
.connect(&config.database_url)
|
||||
.await
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user