o
    gF                     @  s  d dl mZ d dl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lm	Z	 d dlm
Z
 d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl m"Z# ddl m$Z% ddl m&Z& dd l'm(Z( dd!l'm)Z) dd"lm*Z* dd#l+m,Z, dd$l-m.Z. dd%l-m/Z/ erCdd&l0m1Z1 dd'l2m3Z3 dd(l2m4Z4 dd)l2m5Z5 dd*l2m6Z6 dd+l2m7Z7 dd,l2m8Z8 dd-l2m9Z9 dd.l2m:Z: dd/l2m;Z; dd0l<m=Z= dd1l>m?Z? dd2l@mAZA dd3l@mBZB dd4lCmDZD dd5lEmFZF dd6lGmHZH e/d7ZIed8ed9ZJdkd@dAZK	BdldmdHdIZLdndKdLZMG dMdN dNZNejOe!dOdPg g g dQdRG dSdT dTee! edT eNZPejOe&dUdVg g dWg dXdRG dYd? d?ee& eNZQG dZd[ d[ee) ed[ ZRedod^d_ZSedpdad_ZSdqddd_ZSeTePdrdgdhZUeTeQdsdidjZVdS )t    )annotationsN)Any)AsyncIterator)Callable)Dict)	Generator)NoReturn)Optional)overload)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )exc)asyncstartablecontext)GeneratorStartableContext)ProxyComparable)StartableContext)_ensure_sync_result)AsyncResult)AsyncScalarResult   )
inspection)util)
Connection)create_engine)create_pool_from_url)Engine)NestedTransaction)Transaction)ArgumentError)greenlet_spawn)Concatenate)	ParamSpec)CursorResult)_CoreAnyExecuteParams)_CoreSingleExecuteParams)_DBAPIAnyExecuteParams)_ExecuteOptions)CompiledCacheType)CoreExecuteOptionsParameter)Dialect)IsolationLevel)SchemaTranslateMapType)ScalarResult)URL)Pool)PoolProxiedConnection)	_InfoType)
Executable)TypedReturnsRows_P_T)boundurlUnion[str, URL]kwr   returnAsyncEnginec                   sr   | ddrtdd|d< |dd  r-| ddr!td	d fdd}||d< t| fi |tS )a  Create a new async engine instance.

    Arguments passed to :func:`_asyncio.create_async_engine` are mostly
    identical to those passed to the :func:`_sa.create_engine` function.
    The specified dialect must be an asyncio-compatible dialect
    such as :ref:`dialect-postgresql-asyncpg`.

    .. versionadded:: 1.4

    :param async_creator: an async callable which returns a driver-level
        asyncio connection. If given, the function should take no arguments,
        and return a new asyncio connection from the underlying asyncio
        database driver; the connection will be wrapped in the appropriate
        structures to be used with the :class:`.AsyncEngine`.   Note that the
        parameters specified in the URL are not applied here, and the creator
        function should use its own connection parameters.

        This parameter is the asyncio equivalent of the
        :paramref:`_sa.create_engine.creator` parameter of the
        :func:`_sa.create_engine` function.

        .. versionadded:: 2.0.16

    server_side_cursorsFz}Can't set server_side_cursors for async engine globally; use the connection.stream() method for an async streaming result setT	_is_asyncasync_creatorNcreatorz?Can only specify one of 'async_creator' or 'creator', not both.r=   r   c                     s   j jj dS )N)async_creator_fn)dialectdbapiconnect rA   sync_enginerG   _/var/www/html/ecg_monitoring/venv/lib/python3.10/site-packages/sqlalchemy/ext/asyncio/engine.pyrB   o   s   z$create_async_engine.<locals>.creatorr=   r   )get	async_excAsyncMethodRequiredpopr"   _create_enginer>   )r:   r<   rB   rG   rH   rJ   create_async_engineF   s   rQ   sqlalchemy.configurationDict[str, Any]prefixstrkwargsc                   sB    fdd|   D }d|d< || |d}t|fi |S )a  Create a new AsyncEngine instance using a configuration dictionary.

    This function is analogous to the :func:`_sa.engine_from_config` function
    in SQLAlchemy Core, except that the requested dialect must be an
    asyncio-compatible dialect such as :ref:`dialect-postgresql-asyncpg`.
    The argument signature of the function is identical to that
    of :func:`_sa.engine_from_config`.

    .. versionadded:: 1.4.29

    c                   s,   i | ]\}}|  r|t d  |qS N)
startswithlen).0keyvaluerU   rG   rJ   
<dictcomp>   s    z,async_engine_from_config.<locals>.<dictcomp>T_coerce_configr:   )itemsupdaterO   rQ   )rS   rU   rW   optionsr:   rG   r^   rJ   async_engine_from_config|   s   


rd   r2   c                 K  s   d|d< t | fi |S )aV  Create a new async engine instance.

    Arguments passed to :func:`_asyncio.create_async_pool_from_url` are mostly
    identical to those passed to the :func:`_sa.create_pool_from_url` function.
    The specified dialect must be an asyncio-compatible dialect
    such as :ref:`dialect-postgresql-asyncpg`.

    .. versionadded:: 2.0.10

    Tr@   )_create_pool_from_url)r:   rW   rG   rG   rJ   create_async_pool_from_url   s   rf   c                   @  s   e Zd ZdZedddZdS )AsyncConnectable)_slots_dispatch__weakref__r=   r   c                 C  s   t d)Nzasynchronous events are not implemented at this time.  Apply synchronous listeners to the AsyncEngine.sync_engine or AsyncConnection.sync_connection attributes.)NotImplementedError)clsrG   rG   rJ   _no_async_engine_events   s   z(AsyncConnectable._no_async_engine_eventsNr=   r   )__name__
__module____qualname__	__slots__classmethodrl   rG   rG   rG   rJ   rg      s    rg   z:class:`_engine.Connection`z!:class:`_asyncio.AsyncConnection`)closedinvalidatedrD   default_isolation_level)classmethodsmethods
attributesc                   @  s  e Zd ZU dZdZ	dddd	Zded< 	 d
ed< 	 edddZ	ddddZ	e
dddZdddZejdddZejddd Zdd"d#Zdd$d%Z	ddd)d*Zdd,d-Zdd.d/Zdd0d1Zdd3d4Zdd5d6Zed7d7d7ddd7d7d7d7dd8
ddIdJZeddKdJZddLdJZddMdNZddOdPZddQdRZddSdTZ		ddd[d\Ze	ddd]ddadbZ e	ddd]ddedbZ e!	ddd]ddgdbZ e	ddd]ddidjZ"e	ddd]ddkdjZ"	ddd]ddldjZ"e	ddd]ddpdqZ#e	ddd]ddrdqZ#	ddd]ddsdqZ#e	ddd]ddudvZ$e	ddd]ddxdvZ$	ddd]ddydvZ$e	ddd]dd{d|Z%e	ddd]dd~d|Z%e!	ddd]ddd|Z%dddZ&dddZ'dddZ(e
dddZ)e
dddZ*e
dddZ+e+j,dddZ+e
dddZ-dS )AsyncConnectiona  An asyncio proxy for a :class:`_engine.Connection`.

    :class:`_asyncio.AsyncConnection` is acquired using the
    :meth:`_asyncio.AsyncEngine.connect`
    method of :class:`_asyncio.AsyncEngine`::

        from sqlalchemy.ext.asyncio import create_async_engine

        engine = create_async_engine("postgresql+asyncpg://user:pass@host/dbname")

        async with engine.connect() as conn:
            result = await conn.execute(select(table))

    .. versionadded:: 1.4

    )enginerI   sync_connectionNasync_enginer>   r{   Optional[Connection]c                 C  s   || _ |j| _| || _d S rX   )rz   rI   _assign_proxiedr{   )selfr|   r{   rG   rG   rJ   __init__   s   zAsyncConnection.__init__r   rI   targetr   r=   c                 C  s   t t|j|S rX   )ry   r>   _retrieve_proxy_for_targetrz   rk   r   rG   rG   rJ   _regenerate_proxy_for_target   s   z,AsyncConnection._regenerate_proxy_for_targetFis_ctxmanagerboolc                   s0   | j r	td| t| jjI dH | _ | S )zzStart this :class:`_asyncio.AsyncConnection` object's context
        outside of using a Python ``with:`` block.

        zconnection is already startedN)r{   r   InvalidRequestErrorr~   r#   rI   rF   r   r   rG   rG   rJ   start  s   
zAsyncConnection.startr   c                 C  s
   t d)zeNot implemented for async; call
        :meth:`_asyncio.AsyncConnection.get_raw_connection`.
        zAsyncConnection.connection accessor is not implemented as the attribute may need to reconnect on an invalidated connection.  Use the get_raw_connection() method.)r   r   r   rG   rG   rJ   
connection  s   zAsyncConnection.connectionr3   c                   s   t t| jdI dH S )a  Return the pooled DBAPI-level connection in use by this
        :class:`_asyncio.AsyncConnection`.

        This is a SQLAlchemy connection-pool proxied connection
        which then has the attribute
        :attr:`_pool._ConnectionFairy.driver_connection` that refers to the
        actual driver connection. Its
        :attr:`_pool._ConnectionFairy.dbapi_connection` refers instead
        to an :class:`_engine.AdaptedConnection` instance that
        adapts the driver connection to the DBAPI protocol.

        r   N)r#   getattr_proxiedr   rG   rG   rJ   get_raw_connection!  s   z"AsyncConnection.get_raw_connectionr4   c                 C     | j jS )a  Return the :attr:`_engine.Connection.info` dictionary of the
        underlying :class:`_engine.Connection`.

        This dictionary is freely writable for user-defined state to be
        associated with the database connection.

        This attribute is only available if the :class:`.AsyncConnection` is
        currently connected.   If the :attr:`.AsyncConnection.closed` attribute
        is ``True``, then accessing this attribute will raise
        :class:`.ResourceClosedError`.

        .. versionadded:: 1.4.0b2

        )r   infor   rG   rG   rJ   r   1  s   zAsyncConnection.infoc                 C     | j s|   | j S rX   )r{   _raise_for_not_startedr   rG   rG   rJ   r   C     zAsyncConnection._proxiedAsyncTransactionc                 C  s   | j sJ t| S )z1Begin a transaction prior to autobegin occurring.r   r   r   rG   rG   rJ   beginI  s   
zAsyncConnection.beginc                 C  s   | j sJ t| ddS )z;Begin a nested transaction and return a transaction handle.T)nestedr   r   rG   rG   rJ   begin_nestedN  s   
zAsyncConnection.begin_nested	exceptionOptional[BaseException]Nonec                   s   t | jj|dI dH S )zInvalidate the underlying DBAPI connection associated with
        this :class:`_engine.Connection`.

        See the method :meth:`_engine.Connection.invalidate` for full
        detail on this method.

        )r   N)r#   r   
invalidate)r   r   rG   rG   rJ   r   S  s   zAsyncConnection.invalidater.   c                   s   t | jjI d H S rX   )r#   r   get_isolation_levelr   rG   rG   rJ   r   b  s   z#AsyncConnection.get_isolation_levelc                 C  
   | j  S )z,Return True if a transaction is in progress.)r   in_transactionr   rG   rG   rJ   r   e  s   
zAsyncConnection.in_transactionc                 C  r   )zYReturn True if a transaction is in progress.

        .. versionadded:: 1.4.0b2

        )r   in_nested_transactionr   rG   rG   rJ   r   j  s   
z%AsyncConnection.in_nested_transactionOptional[AsyncTransaction]c                 C      | j  }|durt|S dS )a  Return an :class:`.AsyncTransaction` representing the current
        transaction, if any.

        This makes use of the underlying synchronous connection's
        :meth:`_engine.Connection.get_transaction` method to get the current
        :class:`_engine.Transaction`, which is then proxied in a new
        :class:`.AsyncTransaction` object.

        .. versionadded:: 1.4.0b2

        N)r   get_transactionr   r   r   transrG   rG   rJ   r   r     

zAsyncConnection.get_transactionc                 C  r   )a  Return an :class:`.AsyncTransaction` representing the current
        nested (savepoint) transaction, if any.

        This makes use of the underlying synchronous connection's
        :meth:`_engine.Connection.get_nested_transaction` method to get the
        current :class:`_engine.Transaction`, which is then proxied in a new
        :class:`.AsyncTransaction` object.

        .. versionadded:: 1.4.0b2

        N)r   get_nested_transactionr   r   r   rG   rG   rJ   r     r   z&AsyncConnection.get_nested_transaction.)
compiled_cachelogging_tokenisolation_levelno_parametersstream_resultsmax_row_buffer	yield_perinsertmanyvalues_page_sizeschema_translate_mappreserve_rowcountr   Optional[CompiledCacheType]r   rV   r   r   r   r   intr   r   r    Optional[SchemaTranslateMapType]r   optr   c       
              d S rX   rG   )r   r   r   r   r   r   r   r   r   r   r   r   rG   rG   rJ   execution_options  s   z!AsyncConnection.execution_optionsc                   r   rX   rG   r   r   rG   rG   rJ   r     s   c                   s0   | j }t|jfi |I dH }||u sJ | S )a'  Set non-SQL options for the connection which take effect
        during execution.

        This returns this :class:`_asyncio.AsyncConnection` object with
        the new options added.

        See :meth:`_engine.Connection.execution_options` for full details
        on this method.

        N)r   r#   r   )r   r   connc2rG   rG   rJ   r     s
   c                      t | jjI dH  dS )a  Commit the transaction that is currently in progress.

        This method commits the current transaction if one has been started.
        If no transaction was started, the method has no effect, assuming
        the connection is in a non-invalidated state.

        A transaction is begun on a :class:`_engine.Connection` automatically
        whenever a statement is first executed, or when the
        :meth:`_engine.Connection.begin` method is called.

        Nr#   r   commitr   rG   rG   rJ   r     s   zAsyncConnection.commitc                   r   )a&  Roll back the transaction that is currently in progress.

        This method rolls back the current transaction if one has been started.
        If no transaction was started, the method has no effect.  If a
        transaction was started and the connection is in an invalidated state,
        the transaction is cleared using this method.

        A transaction is begun on a :class:`_engine.Connection` automatically
        whenever a statement is first executed, or when the
        :meth:`_engine.Connection.begin` method is called.


        Nr#   r   rollbackr   rG   rG   rJ   r     s   zAsyncConnection.rollbackc                   r   )zClose this :class:`_asyncio.AsyncConnection`.

        This has the effect of also rolling back the transaction if one
        is in place.

        Nr#   r   closer   rG   rG   rJ   r     s   zAsyncConnection.closec                   s   |   I dH  dS )a  A synonym for :meth:`_asyncio.AsyncConnection.close`.

        The :meth:`_asyncio.AsyncConnection.aclose` name is specifically
        to support the Python standard library ``@contextlib.aclosing``
        context manager function.

        .. versionadded:: 2.0.20

        Nr   r   rG   rG   rJ   aclose  s   
zAsyncConnection.aclose	statement
parameters Optional[_DBAPIAnyExecuteParams]r   %Optional[CoreExecuteOptionsParameter]CursorResult[Any]c                   0   t | jj|||ddI dH }t|| jI dH S )zaExecutes a driver-level SQL string and return buffered
        :class:`_engine.Result`.

        T)_require_awaitN)r#   r   exec_driver_sqlr   r   r   r   r   resultrG   rG   rJ   r     s   zAsyncConnection.exec_driver_sqlr   TypedReturnsRows[_T]Optional[_CoreAnyExecuteParams]*GeneratorStartableContext[AsyncResult[_T]]c                C     d S rX   rG   r   r   r   r   rG   rG   rJ   stream     zAsyncConnection.streamr5   +GeneratorStartableContext[AsyncResult[Any]]c                C  r   rX   rG   r   rG   rG   rJ   r     r   AsyncIterator[AsyncResult[Any]]c             	   C s   | j js
tdt| jj||tj	|ddiddI dH }|j
js%J t|}z|V  W n
 ty8   Y dS w t| }t|I dH  dS )aK  Execute a statement and return an awaitable yielding a
        :class:`_asyncio.AsyncResult` object.

        E.g.::

            result = await conn.stream(stmt)
            async for row in result:
                print(f"{row}")

        The :meth:`.AsyncConnection.stream`
        method supports optional context manager use against the
        :class:`.AsyncResult` object, as in::

            async with conn.stream(stmt) as result:
                async for row in result:
                    print(f"{row}")

        In the above pattern, the :meth:`.AsyncResult.close` method is
        invoked unconditionally, even if the iterator is interrupted by an
        exception throw.   Context manager use remains optional, however,
        and the function may be called in either an ``async with fn():`` or
        ``await fn()`` style.

        .. versionadded:: 2.0.0b3 added context manager support


        :return: an awaitable object that will yield an
         :class:`_asyncio.AsyncResult` object.

        .. seealso::

            :meth:`.AsyncConnection.stream_scalars`

        zmCant use `stream` or `stream_scalars` with the current dialect since it does not support server side cursors.r   Tr   r   N)rD   supports_server_side_cursorsr   r   r#   r   executer   
EMPTY_DICT
merge_withcontext_is_server_sider   GeneratorExitasynciocreate_taskr   shield)r   r   r   r   r   artaskrG   rG   rJ   r     s.   *	
CursorResult[_T]c                  r   rX   rG   r   rG   rG   rJ   r   Z     zAsyncConnection.executec                  r   rX   rG   r   rG   rG   rJ   r   c  r   c                  r   )a  Executes a SQL statement construct and return a buffered
        :class:`_engine.Result`.

        :param object: The statement to be executed.  This is always
         an object that is in both the :class:`_expression.ClauseElement` and
         :class:`_expression.Executable` hierarchies, including:

         * :class:`_expression.Select`
         * :class:`_expression.Insert`, :class:`_expression.Update`,
           :class:`_expression.Delete`
         * :class:`_expression.TextClause` and
           :class:`_expression.TextualSelect`
         * :class:`_schema.DDL` and objects which inherit from
           :class:`_schema.ExecutableDDLElement`

        :param parameters: parameters which will be bound into the statement.
         This may be either a dictionary of parameter names to values,
         or a mutable sequence (e.g. a list) of dictionaries.  When a
         list of dictionaries is passed, the underlying statement execution
         will make use of the DBAPI ``cursor.executemany()`` method.
         When a single dictionary is passed, the DBAPI ``cursor.execute()``
         method will be used.

        :param execution_options: optional dictionary of execution options,
         which will be associated with the statement execution.  This
         dictionary can provide a subset of the options that are accepted
         by :meth:`_engine.Connection.execution_options`.

        :return: a :class:`_engine.Result` object.

        Tr   N)r#   r   r   r   r   rG   rG   rJ   r   l  s   &TypedReturnsRows[Tuple[_T]]"Optional[_CoreSingleExecuteParams]Optional[_T]c                  r   rX   rG   r   rG   rG   rJ   scalar  r   zAsyncConnection.scalarc                  r   rX   rG   r   rG   rG   rJ   r     r   c                      | j |||dI dH }| S )au  Executes a SQL statement construct and returns a scalar object.

        This method is shorthand for invoking the
        :meth:`_engine.Result.scalar` method after invoking the
        :meth:`_engine.Connection.execute` method.  Parameters are equivalent.

        :return: a scalar Python value representing the first column of the
         first row returned.

        r   N)r   r   r   rG   rG   rJ   r     s
   ScalarResult[_T]c                  r   rX   rG   r   rG   rG   rJ   scalars  r   zAsyncConnection.scalarsScalarResult[Any]c                  r   rX   rG   r   rG   rG   rJ   r     r   c                  r   )ai  Executes a SQL statement construct and returns a scalar objects.

        This method is shorthand for invoking the
        :meth:`_engine.Result.scalars` method after invoking the
        :meth:`_engine.Connection.execute` method.  Parameters are equivalent.

        :return: a :class:`_engine.ScalarResult` object.

        .. versionadded:: 1.4.24

        r   N)r   r   r   rG   rG   rJ   r     s
   0GeneratorStartableContext[AsyncScalarResult[_T]]c                C  r   rX   rG   r   rG   rG   rJ   stream_scalars  r   zAsyncConnection.stream_scalars1GeneratorStartableContext[AsyncScalarResult[Any]]c                C  r   rX   rG   r   rG   rG   rJ   r     r   %AsyncIterator[AsyncScalarResult[Any]]c             	   C sV   | j |||d4 I dH }| V  W d  I dH  dS 1 I dH s$w   Y  dS )af  Execute a statement and return an awaitable yielding a
        :class:`_asyncio.AsyncScalarResult` object.

        E.g.::

            result = await conn.stream_scalars(stmt)
            async for scalar in result:
                print(f"{scalar}")

        This method is shorthand for invoking the
        :meth:`_engine.AsyncResult.scalars` method after invoking the
        :meth:`_engine.Connection.stream` method.  Parameters are equivalent.

        The :meth:`.AsyncConnection.stream_scalars`
        method supports optional context manager use against the
        :class:`.AsyncScalarResult` object, as in::

            async with conn.stream_scalars(stmt) as result:
                async for scalar in result:
                    print(f"{scalar}")

        In the above pattern, the :meth:`.AsyncScalarResult.close` method is
        invoked unconditionally, even if the iterator is interrupted by an
        exception throw.  Context manager use remains optional, however,
        and the function may be called in either an ``async with fn():`` or
        ``await fn()`` style.

        .. versionadded:: 2.0.0b3 added context manager support

        :return: an awaitable object that will yield an
         :class:`_asyncio.AsyncScalarResult` object.

        .. versionadded:: 1.4.24

        .. seealso::

            :meth:`.AsyncConnection.stream`

        r   N)r   r   r   rG   rG   rJ   r     s   0.fn)Callable[Concatenate[Connection, _P], _T]arg_P.argsr<   	_P.kwargsr8   c                   s&   t || jg|R ddi|I dH S )aa	  Invoke the given synchronous (i.e. not async) callable,
        passing a synchronous-style :class:`_engine.Connection` as the first
        argument.

        This method allows traditional synchronous SQLAlchemy functions to
        run within the context of an asyncio application.

        E.g.::

            def do_something_with_core(conn: Connection, arg1: int, arg2: str) -> str:
                """A synchronous function that does not require awaiting

                :param conn: a Core SQLAlchemy Connection, used synchronously

                :return: an optional return value is supported

                """
                conn.execute(some_table.insert().values(int_col=arg1, str_col=arg2))
                return "success"


            async def do_something_async(async_engine: AsyncEngine) -> None:
                """an async function that uses awaiting"""

                async with async_engine.begin() as async_conn:
                    # run do_something_with_core() with a sync-style
                    # Connection, proxied into an awaitable
                    return_code = await async_conn.run_sync(
                        do_something_with_core, 5, "strval"
                    )
                    print(return_code)

        This method maintains the asyncio event loop all the way through
        to the database connection by running the given callable in a
        specially instrumented greenlet.

        The most rudimentary use of :meth:`.AsyncConnection.run_sync` is to
        invoke methods such as :meth:`_schema.MetaData.create_all`, given
        an :class:`.AsyncConnection` that needs to be provided to
        :meth:`_schema.MetaData.create_all` as a :class:`_engine.Connection`
        object::

            # run metadata.create_all(conn) with a sync-style Connection,
            # proxied into an awaitable
            with async_engine.begin() as conn:
                await conn.run_sync(metadata.create_all)

        .. note::

            The provided callable is invoked inline within the asyncio event
            loop, and will block on traditional IO calls.  IO within this
            callable should only call into SQLAlchemy's asyncio database
            APIs which will be properly adapted to the greenlet context.

        .. seealso::

            :meth:`.AsyncSession.run_sync`

            :ref:`session_run_sync`

        r   FN)r#   r   )r   r   r   r<   rG   rG   rJ   run_sync3  s   DzAsyncConnection.run_sync%Generator[Any, None, AsyncConnection]c                 C  s   |    S rX   )r   	__await__r   rG   rG   rJ   r   {  s   zAsyncConnection.__await__type_r]   	tracebackc                   s$   t |  }t |I d H  d S rX   )r   r   r   r   )r   r   r]   r   r   rG   rG   rJ   	__aexit__~  s   zAsyncConnection.__aexit__c                 C  r   )zReturn True if this connection is closed.

        .. container:: class_bases

            Proxied for the :class:`_engine.Connection` class
            on behalf of the :class:`_asyncio.AsyncConnection` class.

        )r   rs   r   rG   rG   rJ   rs     s   zAsyncConnection.closedc                 C  r   )aT  Return True if this connection was invalidated.

        .. container:: class_bases

            Proxied for the :class:`_engine.Connection` class
            on behalf of the :class:`_asyncio.AsyncConnection` class.

        This does not indicate whether or not the connection was
        invalidated at the pool level, however


        )r   rt   r   rG   rG   rJ   rt        zAsyncConnection.invalidatedr-   c                 C  r   )zProxy for the :attr:`_engine.Connection.dialect` attribute
        on behalf of the :class:`_asyncio.AsyncConnection` class.

        r   rD   r   rG   rG   rJ   rD        zAsyncConnection.dialectattrc                 C     || j _d S rX   r   r   r  rG   rG   rJ   rD        c                 C  r   )a  The initial-connection time isolation level associated with the
        :class:`_engine.Dialect` in use.

        .. container:: class_bases

            Proxied for the :class:`_engine.Connection` class
            on behalf of the :class:`_asyncio.AsyncConnection` class.

        This value is independent of the
        :paramref:`.Connection.execution_options.isolation_level` and
        :paramref:`.Engine.execution_options.isolation_level` execution
        options, and is determined by the :class:`_engine.Dialect` when the
        first connection is created, by performing a SQL query against the
        database for the current isolation level before any additional commands
        have been emitted.

        Calling this accessor does not invoke any new SQL queries.

        .. seealso::

            :meth:`_engine.Connection.get_isolation_level`
            - view current actual isolation level

            :paramref:`_sa.create_engine.isolation_level`
            - set per :class:`_engine.Engine` isolation level

            :paramref:`.Connection.execution_options.isolation_level`
            - set per :class:`_engine.Connection` isolation level


        )r   ru   r   rG   rG   rJ   ru     s   "z'AsyncConnection.default_isolation_levelrX   )r|   r>   r{   r}   )r   r   r=   ry   F)r   r   r=   ry   rm   r=   r3   )r=   r4   )r=   r   )r=   r   )r   r   r=   r   )r=   r.   r=   r   )r=   r   )r   r   r   rV   r   r.   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r=   ry   )r   r   r=   ry   r=   r   )NN)r   rV   r   r   r   r   r=   r   )r   r   r   r   r   r   r=   r   )r   r5   r   r   r   r   r=   r   )r   r5   r   r   r   r   r=   r   )r   r   r   r   r   r   r=   r   )r   r5   r   r   r   r   r=   r   )r   r   r   r   r   r   r=   r   )r   r5   r   r   r   r   r=   r   )r   r   r   r   r   r   r=   r   )r   r5   r   r   r   r   r=   r   )r   r   r   r   r   r   r=   r   )r   r5   r   r   r   r   r=   r   )r   r5   r   r   r   r   r=   r   )r   r   r   r   r<   r   r=   r8   )r=   r   r   r   r]   r   r   r   r=   r   rK   r=   r-   r  r-   r=   r   ).rn   ro   rp   __doc__rq   r   __annotations__rr   r   r   propertyr   r   r   ro_non_memoized_propertyr   r   r   r   r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rs   rt   rD   setterru   rG   rG   rG   rJ   ry      s  
 		













	B/
4
H
	ry   z:class:`_engine.Engine`z:class:`_asyncio.AsyncEngine`)clear_compiled_cacheupdate_execution_optionsget_execution_options)r:   poolrD   rz   namedriverechoc                   @  sx  e Zd ZU dZdZeZded< ded< 	 dMddZe	j
dNd	d
ZedOddZejdPddZdQddZdRddZedddddddSd%d&ZedTd'd&ZdTd(d&ZdUdVd-d.ZdWd/d0ZdXd1d2ZdYd4d5ZedZd7d8Zejd[d:d8Zed\d<d=Zejd]d>d=Zed^d@dAZejd_dBdAZed`dCdDZed`dEdFZed`dGdHZ ed`dIdJZ!e!jdadKdJZ!dLS )br>   aQ  An asyncio proxy for a :class:`_engine.Engine`.

    :class:`_asyncio.AsyncEngine` is acquired using the
    :func:`_asyncio.create_async_engine` function::

        from sqlalchemy.ext.asyncio import create_async_engine

        engine = create_async_engine("postgresql+asyncpg://user:pass@host/dbname")

    .. versionadded:: 1.4

    rI   zType[AsyncConnection]_connection_clsr   c                 C  s.   |j jstd|j jd| || _d S )NzFThe asyncio extension requires an async driver to be used. The loaded z is not async.)rD   is_asyncr   r   r  r~   rI   )r   rI   rG   rG   rJ   r     s   zAsyncEngine.__init__r=   c                 C  s   | j S rX   )rI   r   rG   rG   rJ   r     s   zAsyncEngine._proxiedr   c                 C  s   t |S rX   )r>   r   rG   rG   rJ   r        z(AsyncEngine._regenerate_proxy_for_targetAsyncIterator[AsyncConnection]c              
   C s   |   }|4 I dH - | 4 I dH  |V  W d  I dH  n1 I dH s(w   Y  W d  I dH  dS 1 I dH s>w   Y  dS )a  Return a context manager which when entered will deliver an
        :class:`_asyncio.AsyncConnection` with an
        :class:`_asyncio.AsyncTransaction` established.

        E.g.::

            async with async_engine.begin() as conn:
                await conn.execute(
                    text("insert into table (x, y, z) values (1, 2, 3)")
                )
                await conn.execute(text("my_special_procedure(5)"))

        N)rF   r   )r   r   rG   rG   rJ   r     s   *.zAsyncEngine.beginry   c                 C  s
   |  | S )a  Return an :class:`_asyncio.AsyncConnection` object.

        The :class:`_asyncio.AsyncConnection` will procure a database
        connection from the underlying connection pool when it is entered
        as an async context manager::

            async with async_engine.connect() as conn:
                result = await conn.execute(select(user_table))

        The :class:`_asyncio.AsyncConnection` may also be started outside of a
        context manager by invoking its :meth:`_asyncio.AsyncConnection.start`
        method.

        )r  r   rG   rG   rJ   rF   ,     
zAsyncEngine.connectr3   c                   s   t | jjI dH S )zReturn a "raw" DBAPI connection from the connection pool.

        .. seealso::

            :ref:`dbapi_connections`

        N)r#   rI   raw_connectionr   rG   rG   rJ   r  >  s   zAsyncEngine.raw_connection.)r   r   r   r   r   r   r   r   rV   r   r.   r   r   r   r   r   r   c                K  r   rX   rG   )r   r   r   r   r   r   r   rG   rG   rJ   r   H  s   
zAsyncEngine.execution_optionsc                 K  r   rX   rG   r   rG   rG   rJ   r   T     c                 K  s   t | jjdi |S )a  Return a new :class:`_asyncio.AsyncEngine` that will provide
        :class:`_asyncio.AsyncConnection` objects with the given execution
        options.

        Proxied from :meth:`_engine.Engine.execution_options`.  See that
        method for details.

        NrG   )r>   rI   r   r   rG   rG   rJ   r   W  s   
Tr   r   r   c                   s   t | jj|dI dH  dS )aE  Dispose of the connection pool used by this
        :class:`_asyncio.AsyncEngine`.

        :param close: if left at its default of ``True``, has the
         effect of fully closing all **currently checked in**
         database connections.  Connections that are still checked out
         will **not** be closed, however they will no longer be associated
         with this :class:`_engine.Engine`,
         so when they are closed individually, eventually the
         :class:`_pool.Pool` which they are associated with will
         be garbage collected and they will be closed out fully, if
         not already closed on checkin.

         If set to ``False``, the previous connection pool is de-referenced,
         and otherwise not touched in any way.

        .. seealso::

            :meth:`_engine.Engine.dispose`

        r   N)r#   rI   dispose)r   r   rG   rG   rJ   r  c  s   zAsyncEngine.disposec                 C  r   )a-  Clear the compiled cache associated with the dialect.

        .. container:: class_bases

            Proxied for the :class:`_engine.Engine` class on
            behalf of the :class:`_asyncio.AsyncEngine` class.

        This applies **only** to the built-in cache that is established
        via the :paramref:`_engine.create_engine.query_cache_size` parameter.
        It will not impact any dictionary caches that were passed via the
        :paramref:`.Connection.execution_options.compiled_cache` parameter.

        .. versionadded:: 1.4


        )r   r  r   rG   rG   rJ   r    s   
z AsyncEngine.clear_compiled_cachec                 K  s   | j jdi |S )a  Update the default execution_options dictionary
        of this :class:`_engine.Engine`.

        .. container:: class_bases

            Proxied for the :class:`_engine.Engine` class on
            behalf of the :class:`_asyncio.AsyncEngine` class.

        The given keys/values in \**opt are added to the
        default execution options that will be used for
        all connections.  The initial contents of this dictionary
        can be sent via the ``execution_options`` parameter
        to :func:`_sa.create_engine`.

        .. seealso::

            :meth:`_engine.Connection.execution_options`

            :meth:`_engine.Engine.execution_options`


        NrG   )r   r  r   rG   rG   rJ   r    s   z$AsyncEngine.update_execution_optionsr*   c                 C  r   )aU  Get the non-SQL options which will take effect during execution.

        .. container:: class_bases

            Proxied for the :class:`_engine.Engine` class on
            behalf of the :class:`_asyncio.AsyncEngine` class.

        .. versionadded: 1.3

        .. seealso::

            :meth:`_engine.Engine.execution_options`

        )r   r  r   rG   rG   rJ   r    r  z!AsyncEngine.get_execution_optionsr1   c                 C  r   )zzProxy for the :attr:`_engine.Engine.url` attribute
        on behalf of the :class:`_asyncio.AsyncEngine` class.

        r   r:   r   rG   rG   rJ   r:     r   zAsyncEngine.urlr  c                 C  r  rX   r   r  rG   rG   rJ   r:     r  r2   c                 C  r   )z{Proxy for the :attr:`_engine.Engine.pool` attribute
        on behalf of the :class:`_asyncio.AsyncEngine` class.

        r   r  r   rG   rG   rJ   r    r   zAsyncEngine.poolc                 C  r  rX   r!  r  rG   rG   rJ   r    r  r-   c                 C  r   )z~Proxy for the :attr:`_engine.Engine.dialect` attribute
        on behalf of the :class:`_asyncio.AsyncEngine` class.

        r   r   rG   rG   rJ   rD     r   zAsyncEngine.dialectc                 C  r  rX   r   r  rG   rG   rJ   rD     r  c                 C  r   )aI  Returns this :class:`.Engine`.

        .. container:: class_bases

            Proxied for the :class:`_engine.Engine` class
            on behalf of the :class:`_asyncio.AsyncEngine` class.

        Used for legacy schemes that accept :class:`.Connection` /
        :class:`.Engine` objects within the same variable.


        )r   rz   r   rG   rG   rJ   rz     r   zAsyncEngine.enginec                 C  r   )a  String name of the :class:`~sqlalchemy.engine.interfaces.Dialect`
        in use by this :class:`Engine`.

        .. container:: class_bases

            Proxied for the :class:`_engine.Engine` class
            on behalf of the :class:`_asyncio.AsyncEngine` class.


        )r   r  r   rG   rG   rJ   r       zAsyncEngine.namec                 C  r   )a  Driver name of the :class:`~sqlalchemy.engine.interfaces.Dialect`
        in use by this :class:`Engine`.

        .. container:: class_bases

            Proxied for the :class:`_engine.Engine` class
            on behalf of the :class:`_asyncio.AsyncEngine` class.


        )r   r  r   rG   rG   rJ   r    r"  zAsyncEngine.driverc                 C  r   )a3  When ``True``, enable log output for this element.

        .. container:: class_bases

            Proxied for the :class:`_engine.Engine` class
            on behalf of the :class:`_asyncio.AsyncEngine` class.

        This has the effect of setting the Python logging level for the namespace
        of this element's class and object reference.  A value of boolean ``True``
        indicates that the loglevel ``logging.INFO`` will be set for the logger,
        whereas the string value ``debug`` will set the loglevel to
        ``logging.DEBUG``.

        r   r  r   rG   rG   rJ   r    s   zAsyncEngine.echoc                 C  r  rX   r#  r  rG   rG   rJ   r  *  r  N)rI   r   )r=   r   )r   r   r=   r>   )r=   r  )r=   ry   r  )r   r   r   rV   r   r.   r   r   r   r   r   r   r=   r>   )r   r   r=   r>   )T)r   r   r=   r   r  )r   r   r=   r   )r=   r*   )r=   r1   )r  r1   r=   r   )r=   r2   )r  r2   r=   r   r
  r  rK   )r  r   r=   r   )"rn   ro   rp   r  rq   ry   r  r  r   r   r  r   rr   r   
contextlibasynccontextmanagerr   rF   r  r
   r   r  r  r  r  r  r:   r  r  rD   rz   r  r  r  rG   rG   rG   rJ   r>     sf   
 








c                   @  s   e Zd ZU dZdZded< ded< ded< d(d)d
dZed*ddZe	j
d+ddZed,ddZed,ddZd-ddZd-ddZd-ddZd(d.dd Zd/d%d&Zd'S )0r   z4An asyncio proxy for a :class:`_engine.Transaction`.r   sync_transactionr   zOptional[Transaction]r'  ry   r   r   r   Fc                 C  s   || _ d | _|| _d S rX   r&  )r   r   r   rG   rG   rJ   r   <  s   
zAsyncTransaction.__init__r   r!   r=   c                 C  sP   |j }|}t|t}t|}|d usJ | | }||_ |||_||_|S rX   )	r   
isinstancer    ry   r   __new__r~   r'  r   )rk   r   r{   r'  r   async_connectionobjrG   rG   rJ   r   A  s   

z-AsyncTransaction._regenerate_proxy_for_targetc                 C  r   rX   )r'  r   r   rG   rG   rJ   r   T  r   zAsyncTransaction._proxiedc                 C  r   rX   )r   is_validr   rG   rG   rJ   r,  Z  r  zAsyncTransaction.is_validc                 C  r   rX   )r   	is_activer   rG   rG   rJ   r-  ^  r  zAsyncTransaction.is_activer   c                   r   )a@  Close this :class:`.AsyncTransaction`.

        If this transaction is the base transaction in a begin/commit
        nesting, the transaction will rollback().  Otherwise, the
        method returns.

        This is used to cancel a Transaction without affecting the scope of
        an enclosing transaction.

        Nr   r   rG   rG   rJ   r   b  s   zAsyncTransaction.closec                   r   )z*Roll back this :class:`.AsyncTransaction`.Nr   r   rG   rG   rJ   r   o  s   zAsyncTransaction.rollbackc                   r   )z'Commit this :class:`.AsyncTransaction`.Nr   r   rG   rG   rJ   r   s  s   zAsyncTransaction.commitr   c                   s@   |  t| jr| jjjn| jjjI dH | _|r| j  | S )z{Start this :class:`_asyncio.AsyncTransaction` object's context
        outside of using a Python ``with:`` block.

        N)	r~   r#   r   r   r   r   r   r'  	__enter__r   rG   rG   rJ   r   x  s   
zAsyncTransaction.startr   r   r]   r   c                   s   t | jj|||I d H  d S rX   )r#   r   __exit__)r   r   r]   r   rG   rG   rJ   r     s   zAsyncTransaction.__aexit__Nr  )r   ry   r   r   )r   r!   r=   r   )r=   r!   r  r  )r   r   r=   r   r	  )rn   ro   rp   r  rq   r  r   rr   r   r   r  r   r  r,  r-  r   r   r   r   r   rG   rG   rG   rJ   r   1  s(   
 


r   r|   r   c                 C  r   rX   rG   r|   rG   rG   rJ   _get_sync_engine_or_connection  r  r1  r   c                 C  r   rX   rG   r0  rG   rG   rJ   r1    s   #Union[AsyncEngine, AsyncConnection]Union[Engine, Connection]c              
   C  sB   t | tr| jS z| jW S  ty  } ztd|  |d }~ww )NzAsyncEngine expected, got %r)r(  ry   r   rI   AttributeErrorr   r"   )r|   erG   rG   rJ   r1    s   
subjectr   c                 C     t jddd)NzInspection on an AsyncConnection is currently not supported. Please use ``run_sync`` to pass a callable where it's possible to call ``inspect`` on the passed connection.xd3scoder   NoInspectionAvailabler6  rG   rG   rJ   _no_insp_for_async_conn_yet  s   r>  c                 C  r7  )NzInspection on an AsyncEngine is currently not supported. Please obtain a connection then use ``conn.run_sync`` to pass a callable where it's possible to call ``inspect`` on the passed connection.r8  r9  r;  r=  rG   rG   rJ   _no_insp_for_async_engine_xyet  s   r?  )r:   r;   r<   r   r=   r>   )rR   )rS   rT   rU   rV   rW   r   r=   r>   )r:   r;   rW   r   r=   r2   )r|   r>   r=   r   )r|   ry   r=   r   )r|   r2  r=   r3  )r6  ry   r=   r   )r6  r>   r=   r   )W
__future__r   r   r$  typingr   r   r   r   r   r   r	   r
   r   r   r   r   r    r   rM   baser   r   r   r   r   r   r   r   r   r   rz   r   r   rP   r   re   r   engine.baser    r!   r"   util.concurrencyr#   util.typingr$   r%   engine.cursorr&   engine.interfacesr'   r(   r)   r*   r+   r,   r-   r.   r/   engine.resultr0   
engine.urlr1   r  r2   r3   sql._typingr4   sql.baser5   sql.selectabler6   r7   r8   rQ   rd   rf   rg   create_proxy_methodsry   r>   r   r1  	_inspectsr>  r?  rG   rG   rG   rJ   <module>   s   
7

      "  
N\
