Created
March 1, 2013 21:20
-
-
Save danielholmstrom/5067869 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # vim: set fileencoding=utf-8 : | |
| from __future__ import absolute_import, division | |
| from sqlalchemy import ( | |
| create_engine, | |
| Column, | |
| Integer, | |
| ) | |
| from sqlalchemy.orm import sessionmaker | |
| from sqlalchemy.ext.declarative import declarative_base | |
| engine = create_engine('sqlite://') | |
| Base = declarative_base() | |
| class Model(Base): | |
| __tablename__ = 'model' | |
| id = Column(Integer, primary_key=True) | |
| Base.metadata.create_all(bind=engine) | |
| connection = engine.connect() | |
| Session = sessionmaker(bind=engine) | |
| session = Session() | |
| trans = connection.begin() | |
| assert session.query(Model).count() == 0 | |
| model = Model() | |
| session.add(model) | |
| session.commit() | |
| trans.rollback() | |
| session.close() | |
| connection.close() | |
| session = Session() | |
| assert session.query(Model).count() == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment