Recording Query InformationΒΆ
Warning
This feature is intended for debugging only.
Flask-SQLAlchemy can record some information about every query that executes during a request. This information can then be retrieved to aid in debugging performance. For example, it can reveal that a relationship performed too many individual selects, or reveal a query that took a long time.
To enable this feature, set SQLALCHEMY_RECORD_QUERIES to True in the Flask
app config. Use get_recorded_queries() to get a list of query info objects. Each
object has the following attributes:
statementThe string of SQL generated by SQLAlchemy with parameter placeholders.
parametersThe parameters sent with the SQL statement.
start_time/end_timeTiming info about when the query started execution and when the results where returned. Accuracy and value depends on the operating system.
durationThe time the query took in seconds.
locationA string description of where in your application code the query was executed. This may be unknown in certain cases.