Created
October 10, 2013 19:53
-
-
Save agronholm/6924480 to your computer and use it in GitHub Desktop.
Temporary table hack for SQLAlchemy unit tests
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
def create_temporary_tables(conn, cursor, statement, parameters, context, executemany): | |
if statement.startswith('CREATE TABLE '): | |
statement = 'CREATE TEMPORARY TABLE ' + statement[13:] | |
return statement, parameters | |
def setup_module(): | |
global connection, engine | |
# Connect to the database and create the schema within a transaction | |
engine = create_engine('mysql:///user:pass@yourdb') | |
connection = engine.connect() | |
listen(connection, "before_cursor_execute", create_temporary_tables, retval=True) | |
Base.metadata.create_all(connection) | |
def teardown_module(): | |
# Disconnect from the database | |
connection.close() | |
engine.dispose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment