No project description provided
Project description
PyDto JAVA DTO概念的实现工具
描述
实现DTO层的返回数据结构转换
使用方法
from PyDto.pydto import PyDtoBase
class User(PyDtoBase):
userName:str
password:str
msg:str
class testUser():
userName='userName'
password='password'
msg="here is message"
age=12
if __name__=="__main__":
z:User=User(testUser())
print(z.ResultSchema)
#{userName: userName,password:password,msg:here is message}
使用原则
继承DTO筛选层父类,返回层的结构体实例化传递需要转化的对象或者字典,使用定义好的DTO结构体接受对象
调用ResultSchema方法获取结果
sqlalchemy支持版本
支持sqlalchemy查询结果结构DTO处理,需要进行类的自我拼装
class QuestionDto(PyDtoBase):
id:int
questionText:str
level:int
class AnswerDto(PyDtoBase):
id:int
optionName:str
optionText :str
option :QuestionDto
class Test(PyDtoBase):
id:int
realPhoneNumber:str
phoneNumber :str
# TSRId:str
# businessId :str
# videoSourceId :str
answer:AnswerDto
isSuccess :bool
# created_at :datetime
# updated_at :datetime
兼容查询结构是List或者单个对象,只需要在结构中定义好List或者单个对象的对象结构即可 其他使用方法同上
包安装使用
安装方法:pip install python-dto
类继承模式:
class QuestionDto(PyDtoBase):
id:int
questionText:str
level:int
class AnswerDto(PyDtoBase):
id:int
optionName:str
optionText :str
option :QuestionDto
class Test(PyDtoBase):
id:int
realPhoneNumber:str
phoneNumber :str
# businessId :str
# videoSourceId :str
answer:AnswerDto
isSuccess :bool
# created_at :datetime
# updated_at :datetime
多层级结构嵌套可用,如果类属性为list<Class>的形式,即固定结构数组
参数
| key | description |
|---|---|
| data_mode | sqlalchemy,默认为None,sqlalchemy模式下启动解析schema结构 |
| obj | 传递需要进行数据结构筛选的对象 |
| deep_keep_alive | 计算深度 |
调用方法
z:User=User(testUser())
print(z.ResultSchema)
sqlalchemy建议使用形式
data=[UserDto(sys_user, data_mode="sqlalchemy", deep_keep_alive=1).ResultSchema for sys_user in sys_user_list]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python-dto-0.2.3.tar.gz
(3.9 kB
view details)
File details
Details for the file python-dto-0.2.3.tar.gz.
File metadata
- Download URL: python-dto-0.2.3.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a126d1859a4d57dd0191623c3036fb25477dbb8e67304eeb38f3a768f3a6814d
|
|
| MD5 |
4469998a38efdd57a4792b114c3df819
|
|
| BLAKE2b-256 |
a79bd293771a937872054d76cd3a920e903b12ee2b10a8660cd0a87d588d8663
|