commit() flushes the remaining changes to the database, and commits the transaction. The connection resources referenced by the session are now returned to the connection pool. Subsequent operations with this session will occur in a new transaction, which will again re-acquire connection resources when first needed
filter过滤条件
- equals:
query.filter(User.name == 'ed')
- LIKE
query.filter(User.name.like('%ed%'))
- IN
query.filter(User.name.in_(['ed', 'wendy', 'jack']))
query.filter(User.name.in_(
session.query(User.name).filter(User.name.like('%ed%'))
))
- NOT IN
query.filter(~User.name.in_(['ed', 'wendy', 'jack']))
- AND
from sqlalchemy import and_
query.filter(and_(User.name == 'ed', User.fullname == 'Ed Jones'))