55d95b4c39
新增 db_conn 模块、缓存 schema 初始化、positions 页 commit,风控读库自动重试。 Co-authored-by: Cursor <cursoragent@cursor.com>
20 lines
617 B
Python
20 lines
617 B
Python
"""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
|