feat: optimize model_utils, to_dict and to_obj

This commit is contained in:
martsforever
2026-04-01 22:40:00 +08:00
parent 1a2efee421
commit a17134d5e2
+7 -2
View File
@@ -136,5 +136,10 @@ def to_camel(snake_str: str) -> str:
return components[0] + ''.join(x.title() for x in components[1:]) return components[0] + ''.join(x.title() for x in components[1:])
def to_dict(cls: BaseModel): # 将SqlModel子类实例转化为字典
return cls.model_dump_json(by_alias=True) 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)