Created
December 10, 2017 10:28
-
-
Save dsuch/de67d63ee142f575dcd2a583feb6d572 to your computer and use it in GitHub Desktop.
SA - with rollback - https://bitbucket.org/zzzeek/sqlalchemy/issues/4139/implicit-rollback-and-postgresql-95
This file contains 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
from sqlalchemy import create_engine | |
from sqlalchemy.orm import sessionmaker | |
config = { | |
'username': 'zato1', | |
'password': 'zato1', | |
'database': 'zato1', | |
} | |
url = 'postgresql+pg8000://{username}:{password}@localhost/{database}'.format(**config) | |
engine = create_engine(url, echo=True) | |
conn = engine.connect() | |
Session = sessionmaker(engine) | |
session = Session() | |
result = session.execute('SELECT 1+1') | |
print(result.fetchone()) | |
session.close() | |
""" | |
$ py sa2.py | |
2017-12-10 11:26:04,039 INFO sqlalchemy.engine.base.Engine select version() | |
2017-12-10 11:26:04,039 INFO sqlalchemy.engine.base.Engine () | |
2017-12-10 11:26:04,040 INFO sqlalchemy.engine.base.Engine select current_schema() | |
2017-12-10 11:26:04,040 INFO sqlalchemy.engine.base.Engine () | |
2017-12-10 11:26:04,041 INFO sqlalchemy.engine.base.Engine SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1 | |
2017-12-10 11:26:04,041 INFO sqlalchemy.engine.base.Engine () | |
2017-12-10 11:26:04,042 INFO sqlalchemy.engine.base.Engine SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1 | |
2017-12-10 11:26:04,042 INFO sqlalchemy.engine.base.Engine () | |
2017-12-10 11:26:04,042 INFO sqlalchemy.engine.base.Engine show standard_conforming_strings | |
2017-12-10 11:26:04,042 INFO sqlalchemy.engine.base.Engine () | |
2017-12-10 11:26:04,044 INFO sqlalchemy.engine.base.Engine BEGIN (implicit) | |
2017-12-10 11:26:04,044 INFO sqlalchemy.engine.base.Engine SELECT 1+1 | |
2017-12-10 11:26:04,045 INFO sqlalchemy.engine.base.Engine () | |
(2,) | |
2017-12-10 11:26:04,045 INFO sqlalchemy.engine.base.Engine ROLLBACK | |
$ | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment