Created
August 20, 2013 14:08
-
-
Save vkotovv/6281951 to your computer and use it in GitHub Desktop.
Clear data for all tables via flask-sqlalchemy
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 clear_data(session): | |
meta = db.metadata | |
for table in reversed(meta.sorted_tables): | |
print 'Clear table %s' % table | |
session.execute(table.delete()) | |
session.commit() |
what is the session datatype?
@NailClaros In case you need to call the clear_data function by passing the session_datatype, you can use:
clear_data(db.session)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It will spend a lot of time if u doing some like that often. For example, u can use author's code in tests, where u need to clear all tables after commits. Imagine u have 30-40 tests. How much time it will spend?