基本查询
# 查询所有用户数据
User.query.all() # 返回列表, 元素为模型对象
# 查询有多少个用户
User.query.count()
# 查询第1个用户
User.query.first() # 返回模型对象/None
# 查询id为4的用户[3种方式]
User.query.get(4) # 根据id查询,返回模型对象/None
# BaseQuery对象可以续接具体查询条件 all/count/first
User.query.filter_by(id=4).all() # 简单查询器 关键字实参设置字段值 返回BaseQuery对象
User.query.filter(User.id == 4).first() # 复杂查询器 参数为比较运算/函数引用等 返回BaseQuery对象
# 查询名字结尾字符为g的所有用户[开始 / 包含]
User.query.filter(User.name.endswith("g")).all()
User.query.filter(User.name.startswith("g")).all()
User.query.filter(User.name.contains("n")).all()
User.query.filter(User.name.like("w%n%g")).all() # 模糊查询
# 查询名字和邮箱都以li开头的所有用户[2种方式]
User.query.filter(User.name.startswith('li'), User.email.startswith('li'))