Skip to content

Instantly share code, notes, and snippets.

@stabacco
Last active March 24, 2022 22:32
Show Gist options
  • Save stabacco/fb660f4f66a57d0b4f7e47710afb20b2 to your computer and use it in GitHub Desktop.
Save stabacco/fb660f4f66a57d0b4f7e47710afb20b2 to your computer and use it in GitHub Desktop.
sqlalchemy debug queries
@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