Add: Sqlite Connect Options
Build and Push Docker Image / build_docker_image (push) Successful in 13m50s

This commit is contained in:
2025-10-22 13:39:29 +09:00
parent a59235cb8c
commit 7dbca66b2f
+13 -3
View File
@@ -11,6 +11,7 @@ use log::info;
use sqlx::sqlite::SqlitePool;
use std::collections::HashMap;
use std::env;
use std::str::FromStr;
use std::sync::Arc;
use tokio::net::TcpListener;
use tokio::sync::{RwLock, broadcast};
@@ -27,9 +28,18 @@ async fn main() -> Result<()> {
// 数据库初始化
let db_path = env::var("DB_PATH").unwrap_or_else(|_| DEFAULT_DB_PATH.to_string());
let db_url = format!("sqlite://{}", db_path);
let pool = SqlitePool::connect(&db_url).await?;
info!("Database pool connected successfully to {}", db_url);
let pool = sqlx::sqlite::SqlitePoolOptions::new()
.max_connections(100)
.acquire_timeout(std::time::Duration::from_secs(30))
.connect_with(
sqlx::sqlite::SqliteConnectOptions::new()
.filename(&db_path)
.create_if_missing(true)
.foreign_keys(true)
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal),
)
.await?;
info!("Database pool connected successfully to {}", db_path);
database::init_database(&pool).await?; // 使用 database 模块的函数
let pool = Arc::new(pool); // 将 SqlitePool 包裹在 Arc 中,以便多线程共享
info!("Connected to SQLite");