重构绝大部分模块以适配新版本的数据库和数据模型,修复缺少依赖问题,更新 pyproject
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from typing import Self, TypeVar, Generic, TYPE_CHECKING
|
||||
from dataclasses import is_dataclass
|
||||
from typing import Any, Dict, Self, TypeVar, Generic, TYPE_CHECKING
|
||||
|
||||
import copy
|
||||
|
||||
@@ -15,9 +16,23 @@ class BaseDataModel:
|
||||
return copy.deepcopy(self)
|
||||
|
||||
|
||||
def transform_class_to_dict(obj: Any) -> Dict[str, Any]:
|
||||
if obj is None:
|
||||
return {}
|
||||
if is_dataclass(obj):
|
||||
return obj.__dict__
|
||||
if hasattr(obj, "dict"):
|
||||
return obj.dict()
|
||||
if hasattr(obj, "model_dump"):
|
||||
return obj.model_dump()
|
||||
if hasattr(obj, "__dict__"):
|
||||
return obj.__dict__
|
||||
return {"value": obj}
|
||||
|
||||
|
||||
class BaseDatabaseDataModel(ABC, Generic[T]):
|
||||
@abstractmethod
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def from_db_instance(cls, db_record: T) -> Self:
|
||||
"""从数据库实例创建数据模型对象"""
|
||||
raise NotImplementedError
|
||||
|
||||
Reference in New Issue
Block a user