python orm peewee

安装 peewee

pip install peewee

从数据库生成model
python3 -m pwiz -e mysql -u 名 -H 地址 --password 数据库 > testModel.py
 

输入数据库密码 

建议在linux下生成



查询不到数据会报错 解决用try

try:
    r = App.select().where(AppBlackList.name == 'dai').dicts().get()
except AppBlackList.DoesNotExist:
    print("没有数据")

显示sql

import logging
logger = logging.getLogger('peewee')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())

where 相关

以XX开头

where(App.name.startswith(user_phone))

空值

where(App.name.is_null(True))

order by 相关

order_by(App.addtime.desc())

猜你喜欢

转载自blog.csdn.net/qq_35899407/article/details/85261951