赞
踩
一、查询
- 1. 模型类.query.filter().all() -----> 列表
- 2. 模型类.query.filter().first() -----> 对象
-
- # 等值查询
- User.query.filter_by(username='zhangsan')
-
- # 模糊查询
- # select * from user where username like '%z'
- User.query.filter(User.userName.endswith('z')).all() # 以z结束的
-
- # select * from user where username like 'z%'
- User.query.filter(User.userName.startswith('z')).all() # 以z开始的
-
- # select * from user where username like '%z%'
- User.query.filter(User.userName.contains('z')).all() # 包含
-
- User.query.filter(User.userName.like('z%')).all()
-
-
- ### 多条件查询
- from sqlalchemy import and_, or_, not_ # 导入包
- 并: and_ 或: or_ 非: not_
-
- # select * from user where username like 'z%' or username like '%i%'
- User.query.filter(or_(User.username.like('z%'), User.username.contains('i'))).all()
-
- # select * from user where username like '%i%' and rd
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。