o
    {g                     @  s   d dl mZ d dlZd dlZd dlZd dlmZ d dlZ	d dl
mZ d dlmZ d dlmZ d dlmZ dd	d
ZejG dd dZdddZdddZdddZdS )    )annotationsN)perf_counter)current_app)g)has_app_contextreturnlist[_QueryInfo]c                   C  s   t dg S )a  Get the list of recorded query information for the current session. Queries are
    recorded if the config :data:`.SQLALCHEMY_RECORD_QUERIES` is enabled.

    Each query info 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 not be possible to calculate, and the format is not stable.

    .. versionchanged:: 3.0
        Renamed from ``get_debug_queries``.

    .. versionchanged:: 3.0
        The info object is a dataclass instead of a tuple.

    .. versionchanged:: 3.0
        The info object attribute ``context`` is renamed to ``location``.

    .. versionchanged:: 3.0
        Not enabled automatically in debug or testing mode.
    _sqlalchemy_queries)r   get r   r   a/var/www/html/usg.absolutems/venv/lib/python3.10/site-packages/flask_sqlalchemy/record_queries.pyget_recorded_queries   s   r   c                   @  sH   e Zd ZU dZded< ded< ded< ded< d	ed
< edddZdS )
_QueryInfoa8  Information about an executed query. Returned by :func:`get_recorded_queries`.

    .. versionchanged:: 3.0
        Renamed from ``_DebugQueryTuple``.

    .. versionchanged:: 3.0
        Changed to a dataclass instead of a tuple.

    .. versionchanged:: 3.0
        ``context`` is renamed to ``location``.
    z
str | None	statementt.Any
parametersfloat
start_timeend_timestrlocationr   c                 C  s   | j | j S N)r   r   )selfr   r   r   durationE   s   z_QueryInfo.durationN)r   r   )__name__
__module____qualname____doc____annotations__propertyr   r   r   r   r   r   1   s   
 r   enginesa.engine.EngineNonec                 C  s(   t j| dtdd t j| dtdd d S )Nbefore_cursor_executeT)namedafter_cursor_execute)sa_eventlisten_record_start_record_end)r    r   r   r   _listenJ   s   r*   contextsa.engine.ExecutionContextkwargsr   c                 K  s   t  sd S t | _d S r   )r   r   _fsa_start_time)r+   r-   r   r   r   r(   O   s   r(   c              	   K  s   t  sd S dtvrg t_tjdd }| d}t }|rG|j	d}|rB||ks0|
|rB|j}|j d|j d|j d}n|j}|sd}tjt| j| j| jt |d	 d S )
Nr	   .r   r   :z ()z	<unknown>)r   r   r   r   r   )r   r   r	   r   import_name	partitioninspectcurrentframe	f_globalsr
   
startswithf_codeco_filenamef_linenoco_namef_backappendr   r   r   r.   r   )r+   r-   
import_top
import_dotframenamecoder   r   r   r   r)   V   s2   

r)   )r   r   )r    r!   r   r"   )r+   r,   r-   r   r   r"   )
__future__r   dataclassesr4   typingttimer   
sqlalchemysasqlalchemy.eventeventr&   flaskr   r   r   r   	dataclassr   r*   r(   r)   r   r   r   r   <module>   s     
"

