diff --git a/app/utils/model_utils.py b/app/utils/model_utils.py index d015a2a..c58b849 100644 --- a/app/utils/model_utils.py +++ b/app/utils/model_utils.py @@ -136,5 +136,10 @@ def to_camel(snake_str: str) -> str: return components[0] + ''.join(x.title() for x in components[1:]) -def to_dict(cls: BaseModel): - return cls.model_dump_json(by_alias=True) +# 将SqlModel子类实例转化为字典 +def to_dict(obj: BaseModel): + return obj.model_dump_json(by_alias=True) + +# 将字典转化为SqlModel子类实例对象 +def to_obj(clazz: type[SQLModel], json_data: dict): + return clazz.model_validate(json_data)