0313界面对接

This commit is contained in:
2026-03-13 21:04:19 +08:00
parent 6e74eaf206
commit 8aeaffa885
33 changed files with 1541 additions and 419 deletions

View File

@ -108,14 +108,16 @@ class SQLiteHandler:
"""SQLite数据库操作通用类单例模式"""
_lock = threading.Lock() # 单例锁
_instance = None
_instances = {}
@classmethod
def get_instance(cls, *args, **kwargs):
if cls._instance is None:
def get_instance(cls,db_path, *args, **kwargs):
# 使用文件路径作为键
key = db_path
if key not in cls._instances:
with cls._lock:
if cls._instance is None: # 双重检查
cls._instance = cls(*args, **kwargs)
return cls._instance
if key not in cls._instances: # 双重检查
cls._instances[key] = cls(db_path, *args, **kwargs)
return cls._instances[key]
def __init__(self, db_path: str = "three.db", max_readers: int = 10, busy_timeout: int = 5000):
"""
@ -160,7 +162,7 @@ class SQLiteHandler:
try:
# 创建临时连接来设置参数
conn = sqlite3.connect(self.db_path, **self._connection_params)
# 启用WAL模式Write-Ahead Logging
cursor = conn.execute("PRAGMA journal_mode = WAL")
journal_mode = cursor.fetchone()[0]
@ -184,6 +186,7 @@ class SQLiteHandler:
def _create_connection(self) -> sqlite3.Connection:
"""创建新的数据库连接"""
conn = sqlite3.connect(self.db_path, **self._connection_params)
conn.set_trace_callback(lambda x: print(x))
conn.row_factory = sqlite3.Row
return conn