feat: optimize model_utils, to_dict and to_obj
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user