File: record-queries.rst

package info (click to toggle)
flask-sqlalchemy 3.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 832 kB
  • sloc: python: 2,909; makefile: 27; sh: 14
file content (27 lines) | stat: -rw-r--r-- 1,150 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 :data:`.SQLALCHEMY_RECORD_QUERIES` to ``True`` in the Flask
app config. Use :func:`.get_recorded_queries` to get a list of query info objects. Each
object has the following attributes:

``statement``
    The string of SQL generated by SQLAlchemy with parameter placeholders.
``parameters``
    The parameters sent with the SQL statement.
``start_time`` / ``end_time``
    Timing info about when the query started execution and when the results where
    returned. Accuracy and value depends on the operating system.
``duration``
    The time the query took in seconds.
``location``
    A string description of where in your application code the query was executed. This
    may be unknown in certain cases.