1
This commit is contained in:
BIN
utils/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
utils/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
utils/__pycache__/database_manager.cpython-311.pyc
Normal file
BIN
utils/__pycache__/database_manager.cpython-311.pyc
Normal file
Binary file not shown.
BIN
utils/__pycache__/helpers.cpython-311.pyc
Normal file
BIN
utils/__pycache__/helpers.cpython-311.pyc
Normal file
Binary file not shown.
BIN
utils/__pycache__/redis_batch_helper.cpython-311.pyc
Normal file
BIN
utils/__pycache__/redis_batch_helper.cpython-311.pyc
Normal file
Binary file not shown.
BIN
utils/__pycache__/redis_client.cpython-311.pyc
Normal file
BIN
utils/__pycache__/redis_client.cpython-311.pyc
Normal file
Binary file not shown.
@@ -56,7 +56,7 @@ class DatabaseManager:
|
||||
# 创建表(如果不存在)
|
||||
Base.metadata.create_all(self._engine)
|
||||
|
||||
logger.info("SQLAlchemy数据库引擎初始化成功")
|
||||
# logger.info("SQLAlchemy数据库引擎初始化成功")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"数据库引擎初始化失败: {e}")
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
from typing import List, Dict, Optional, Any
|
||||
from loguru import logger
|
||||
|
||||
|
||||
def safe_float(value, default=0.0):
|
||||
"""安全转换为float,处理None和空值"""
|
||||
if value is None:
|
||||
return default
|
||||
try:
|
||||
return float(value)
|
||||
except (ValueError, TypeError):
|
||||
return default
|
||||
|
||||
def safe_int(value, default=0):
|
||||
"""安全转换为int"""
|
||||
if value is None:
|
||||
return default
|
||||
try:
|
||||
return int(float(value))
|
||||
except (ValueError, TypeError):
|
||||
return default
|
||||
|
||||
def safe_str(self, value: Any, default: str = '') -> str:
|
||||
"""安全转换为str"""
|
||||
if value is None:
|
||||
return ""
|
||||
try:
|
||||
return str(value)
|
||||
except Exception as e:
|
||||
logger.error(f"safe_str error: {e}")
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user