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]
Metadata
Release files for python-dto 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python-dto-0.2.3.tar.gz | 3.9 kB | Without provenance | Details for python-dto-0.2.3.tar.gz |
Release files / python-dto-0.2.3.tar.gz
| Download URL | python-dto-0.2.3.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a126d1859a4d57dd0191623c3036fb25477dbb8e67304eeb38f3a768f3a6814d
|
|
BLAKE2b-256 checksum How to use checksums |
a79bd293771a937872054d76cd3a920e903b12ee2b10a8660cd0a87d588d8663
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for python-dto 0.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.