flask-sqlalchemy如何开启事务?

CPALyth
  • 57

django里开启事务有下面两种语句

  • with transaction.atomic():
  • sid=transaction.savepoint()

flask-sqlalchemy有开启事务的语句吗?

回复
阅读 345
1 个回答
✓ 已被采纳
with Session(engine) as session:
    session.begin()
    try:
        session.add(some_object)
        session.add(some_other_object)
    except:
        session.rollback()
        raise
    else:
        session.commit()
你知道吗?

宣传栏