Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 846 Bytes

File metadata and controls

38 lines (26 loc) · 846 Bytes

Commit / Rollback

sqlalchemy-memory fully supports transactional behavior, including commit and rollback operations. Changes are staged until committed, and can be safely reverted using rollback().

Commit

with SessionFactory() as session:
    session.add(Item(id=1, name="foo"))
    session.commit()

    item = session.get(Item, 1)
    print(item.name) # foo
    item.name = "updated"
    session.commit()

    print(item.name) # updated

Rollback

Use rollback() to undo uncommitted changes:

with SessionFactory() as session:
    session.add(Item(id=1, name="foo"))
    session.commit()

    item = session.get(Item, 1)
    print(item.name) # foo
    item.name = "updated"
    session.rollback()

    print(item.name) # foo