"""SQLite 连接统一配置(WAL + busy_timeout,降低并发锁冲突)。""" from __future__ import annotations import os import sqlite3 DB_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "futures.db") def connect_db(path: str | None = None) -> sqlite3.Connection: db_path = path or DB_PATH conn = sqlite3.connect(db_path, timeout=30, check_same_thread=False) conn.row_factory = sqlite3.Row conn.execute("PRAGMA busy_timeout=30000") try: conn.execute("PRAGMA journal_mode=WAL") except sqlite3.OperationalError: pass return conn