等于
query.filter(User.name == 'xxx')
不等于
query.filter(User.name != 'xxx')
like
query.filter(User.name.like('%xxx%'))
IN查询
query.filter(User.name.in_(['leela', 'akshay', 'santanu']))
NOT IN 查询
query.filter(~User.name.in_(['lee', 'sonal', 'akshay']))
ISNULL
query.filter(User.name.is_(None))
IS NOT NULL
query.filter(User.name.isnot(None))
AND
from sqlalchemy import and_
query.filter(and_(User.name=='xxx', User.sex==1))
或者
from sqlalchemy import and_
query.filter(User.name=='xxx').filter(User.sex==1)
OR
from sqlalchemy import or_
filter(or_(User.name == 'xxx', User.name == 'yyy'))
关注公众号「Python之禅」,回复「1024」免费获取Python资源