Last active
March 24, 2022 22:32
-
-
Save stabacco/fb660f4f66a57d0b4f7e47710afb20b2 to your computer and use it in GitHub Desktop.
sqlalchemy debug queries
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
@app.after_request | |
def after_request(response: flask.Response): | |
from flask_sqlalchemy import get_debug_queries | |
app.config['SQLALCHEMY_RECORD_QUERIES'] = app.config['DEBUG'] | |
app.logger.debug("%s", response.__dict__) | |
count = 0 | |
for query in get_debug_queries(): | |
if query.duration >= 0: | |
count +=1 | |
app.logger.debug("query %s: %s %s %s %s", count, query.statement, query.parameters, query.duration, query.context) | |
app.logger.debug("----") | |
app.logger.info("QUERIES: %s ", count) | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment