flask-sqlachemy note

between

datetime按天查询

 

Myclass.query.filter(myClass.date.between(_date, _date+timedelta(days = 1)))

 

filter 和 filter_by的区别

 

session.query(MyClass).filter(MyClass.name == 'some name')
session.query(MyClass).filter_by(name = 'some name')
 

filter 需要带上tablename,并用==

http://docs.sqlalchemy.org/en/rel_0_7/orm/query.html?highlight=filter_by#sqlalchemy.orm.query.Query.filter

 

 

filter 多个条件的查询


AND操作
刚开始想用惯常的sql查询思维
tablename.filter(condition1 and condition2).all()
 
生成数据后发现condition2完全没有执行。
网上找了个折中的办法:
tablename.fiter(conditon1).filter(condition2).all()
 
虽然达到了想要的效果,但是有种隔靴搔痒的感觉。查找sqlachemy的代码,发现对于查询条件,是放在一个list中进行处理的。各个查询条件之间用‘,’分割:
tablename.filter(condition1,condition2).all
 
OR操作
from sqlachemy import or_
myclass.query.filter(or_(myclass.name=='xk', myclass.country=='china'))
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值