flask_SQLAlchemy filter()跟filter_by()的区别

  • 分类: Python
  • 发表日期:2021-10-08 16:17:00
  • 最后修改:2021-10-08 16:19:00

最近开发使用到flask_SQLAlchemy,遇到filter()跟filter_by(),但是分不清两者区别,通过百度,发现跟自己实践验证不太一样,为此写下这篇博客记录,免得像我等小白被网上一些博客误导!!!

区别1

db.session.query(类名).filter(类名.属性名=='xxx')

db.session.query(类名).filter_by(属性名='xxx')

区别2

网上大部分博客说filter()不能支持组合查询,需要连用filter(),经验证,此说法是不全面的,除了连用filter(),filter()还有以下2,3两种方法可以进行组合查询

1.filter组合查询

①、db.session.query(类名).filter(类名.属性名1=='xxx').filter(类名.属性名2=='xxx')

②、db.session.query(类名).filter(类名.属性名1=='xxx',类名.属性名2=='xxx')

③、db.session.query(类名).filter(and_(类名.属性名1=='xxx',类名.属性名2=='xxx'))

2.filter_by组合查询

①、db.session.query(类名).filter(类名.属性名1=='xxx',类名.属性名2=='xxx')


原文链接:https://blog.csdn.net/qq_26343775/article/details/116003470

 

post
2021年7月9日 09:40 原创 草稿

针对情报平台的多种 es dsl 测试

post
2021年7月13日 09:36 原创
post
2021年7月30日 12:01 原创
post
2021年7月30日 12:15 原创
post
2021年7月30日 15:07 原创
post
2021年7月30日 15:13 原创
post
2021年7月30日 15:18 原创
post
2021年7月30日 15:24 原创
post
2021年7月30日 16:09 原创
post
2021年7月30日 16:02 原创
post
2021年8月16日 15:28 原创
post
2021年8月16日 20:01
post
2021年8月17日 12:07 原创
post
2021年8月31日 15:42 原创
post
2021年10月13日 11:43
post
2021年10月21日 15:47 原创
post
2021年10月25日 11:27

0 评论

大哥整点话呗~