Ë
    r™ãj4  ã                  óÖ  — d 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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r$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(  G d„ d e«      Z) G d!„ d"e«      Z* G d#„ d$ee«      Z+ G d%„ d&e«      Z, G d'„ d(e«      Z- G d)„ d*e«      Z.e.Z/y)+u>  

.. dialect:: sqlite+aiosqlite
    :name: aiosqlite
    :dbapi: aiosqlite
    :connectstring: sqlite+aiosqlite:///file_path
    :url: https://pypi.org/project/aiosqlite/

The aiosqlite dialect provides support for the SQLAlchemy asyncio interface
running on top of pysqlite.

aiosqlite is a wrapper around pysqlite that uses a background thread for
each connection.   It does not actually use non-blocking IO, as SQLite
databases are not socket-based.  However it does provide a working asyncio
interface that's useful for testing and prototyping purposes.

Using a special asyncio mediation layer, the aiosqlite dialect is usable
as the backend for the :ref:`SQLAlchemy asyncio <asyncio_toplevel>`
extension package.

This dialect should normally be used only with the
:func:`_asyncio.create_async_engine` engine creation function::

    from sqlalchemy.ext.asyncio import create_async_engine

    engine = create_async_engine("sqlite+aiosqlite:///filename")

The URL passes through all arguments to the ``pysqlite`` driver, so all
connection arguments are the same as they are for that of :ref:`pysqlite`.

.. _aiosqlite_udfs:

User-Defined Functions
----------------------

aiosqlite extends pysqlite to support async, so we can create our own user-defined functions (UDFs)
in Python and use them directly in SQLite queries as described here: :ref:`pysqlite_udfs`.

.. _aiosqlite_serializable:

Serializable isolation / Savepoints / Transactional DDL (asyncio version)
-------------------------------------------------------------------------

A newly revised version of this important section is now available
at the top level of the SQLAlchemy SQLite documentation, in the section
:ref:`sqlite_transactions`.


.. _aiosqlite_pooling:

Pooling Behavior
----------------

The SQLAlchemy ``aiosqlite`` DBAPI establishes the connection pool differently
based on the kind of SQLite database that's requested:

* When a ``:memory:`` SQLite database is specified, the dialect by default
  will use :class:`.StaticPool`. This pool maintains a single
  connection, so that all access to the engine
  use the same ``:memory:`` database.
* When a file-based database is specified, the dialect will use
  :class:`.AsyncAdaptedQueuePool` as the source of connections.

  .. versionchanged:: 2.0.38

    SQLite file database engines now use :class:`.AsyncAdaptedQueuePool` by default.
    Previously, :class:`.NullPool` were used.  The :class:`.NullPool` class
    may be used by specifying it via the
    :paramref:`_sa.create_engine.poolclass` parameter.

As with the pysqlite dialect, this selection is made based on the database
name alone, and the ``mode=memory`` query string argument is deprecated as
a means of influencing it; see :ref:`pysqlite_threading_pooling` for
background.

.. _aiosqlite_memory:

Using a Memory Database with Multiple Coroutines
-------------------------------------------------

The default :class:`.StaticPool` used for ``:memory:`` databases forces all
coroutines to share a single DBAPI connection.  Because SQLite maintains only
one transaction state per connection, concurrent coroutines can interfere
with each other â€” a ``ROLLBACK`` in one coroutine will also discard
uncommitted work from any other coroutine using the same engine.

For async workloads where multiple :class:`.AsyncSession` or
:class:`.AsyncConnection` objects may be active simultaneously, use SQLite's
shared-cache URI mode instead.  This gives each checkout its own DBAPI
connection with independent transaction state while still sharing one
in-memory database::

    engine = create_async_engine(
        "sqlite+aiosqlite:///file::memory:?cache=shared&uri=true"
    )

Because this URL form is treated as a file-based database by the dialect,
:class:`.AsyncAdaptedQueuePool` is used automatically and no additional
configuration is needed.

Note that a shared-cache database is discarded once its last connection is
closed, so that operations such as :meth:`_asyncio.AsyncEngine.dispose` or
the use of :paramref:`_sa.create_engine.pool_recycle` will destroy its
contents; see :ref:`pysqlite_shared_cache_lifespan` for background and for
how to hold such a database open.

See the pysqlite documentation at
:ref:`pysqlite_uri_shared_cache` for full details on shared-cache memory
databases, including how to use named databases to maintain multiple
independent in-memory databases within the same process.

é    )ÚannotationsN)Úpartial)ÚThread)Ú
ModuleType)ÚAny)Úcast)ÚNoReturn)ÚOptional)ÚTYPE_CHECKING)ÚUnioné   )ÚSQLiteExecutionContext)ÚSQLiteDialect_pysqliteé   )Úpool)Úutil)ÚAsyncAdapt_dbapi_connection)ÚAsyncAdapt_dbapi_cursor)ÚAsyncAdapt_dbapi_module)ÚAsyncAdapt_dbapi_ss_cursor)ÚAsyncAdapt_terminate)Úawait_)ÚAsyncIODBAPIConnection)ÚDBAPIConnection)ÚDBAPICursor)ÚDBAPIModule)ÚURL)ÚPoolProxiedConnectionc                  ó   — e Zd ZdZy)ÚAsyncAdapt_aiosqlite_cursor© N©Ú__name__Ú
__module__Ú__qualname__Ú	__slots__r!   ó    úo/var/www/html/python-recuperauto-other/env/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.pyr    r    ›   ó   „ Ø�Ir'   r    c                  ó   — e Zd ZdZy)ÚAsyncAdapt_aiosqlite_ss_cursorr!   Nr"   r!   r'   r(   r+   r+   Ÿ   r)   r'   r+   c                  ó²   ‡ — e Zd ZdZeZeZedd„«       Z	e	j                  dd„«       Z	dd„Zdˆ fd„Zdˆ fd„Zdd„Ze	 	 	 	 	 	 dˆ fd„«       Zdd	„Zdd
„Zˆ xZS )ÚAsyncAdapt_aiosqlite_connectionr!   c                óJ   — t        t        | j                  j                  «      S ©N)r   ÚstrÚ_connectionÚisolation_level©Úselfs    r(   r2   z/AsyncAdapt_aiosqlite_connection.isolation_level«   s   € ä”C˜×)Ñ)×9Ñ9Ó:Ð:r'   c                óR  — 	 	 	 	 	 	 dd„}t        || j                  j                  |«      }t        j                  «       j                  «       }| j                  j                  j                  ||f«       	 t        |«       y # t        $ r}| j                  |«       Y d }~y d }~ww xY w)Nc                ó   — || _         y r/   )r2   )Ú
connectionÚvalues     r(   Úset_isoz@AsyncAdapt_aiosqlite_connection.isolation_level.<locals>.set_iso¶   s   € ð */ˆJÕ&r'   )r7   r-   r8   úOptional[str]ÚreturnÚNone)r   r1   Ú_connÚasyncioÚget_event_loopÚcreate_futureÚ_txÚ
put_nowaitr   Ú	ExceptionÚ_handle_exception)r4   r8   r9   ÚfunctionÚfutureÚerrors         r(   r2   z/AsyncAdapt_aiosqlite_connection.isolation_level¯   sž   € ð	/Ø7ð	/Ø@Mð	/àó	/ô
 ˜7 D×$4Ñ$4×$:Ñ$:¸EÓBˆÜ×'Ñ'Ó)×7Ñ7Ó9ˆà×Ñ×Ñ×'Ñ'¨°Ð(:Ô;ð	*Ü�6�NøÜò 	*Ø×"Ñ" 5×)Ñ)ûð	*ús   Á6B Â	B&ÂB!Â!B&c                óž   — 	 t         | j                  j                  |i |¤Ž«       y # t        $ r}| j	                  |«       Y d }~y d }~ww xY wr/   )r   r1   Úcreate_functionrC   rD   )r4   ÚargsÚkwrG   s       r(   rI   z/AsyncAdapt_aiosqlite_connection.create_functionÅ   sI   € ð	*ÜÐ3�4×#Ñ#×3Ñ3°TÐ@¸RÑ@ÕAøÜò 	*Ø×"Ñ" 5×)Ñ)ûð	*ús   ‚%( ¨	A±AÁAc                óP   •— | j                   j                   rt        ‰| �	  «        y y r/   )r1   ÚsuperÚrollback©r4   Ú	__class__s    €r(   rN   z(AsyncAdapt_aiosqlite_connection.rollbackË   s"   ø€ Ø×Ñ×'Ò'Ü‰GÑÕð (r'   c                óP   •— | j                   j                   rt        ‰| �	  «        y y r/   )r1   rM   ÚcommitrO   s    €r(   rR   z&AsyncAdapt_aiosqlite_connection.commitÏ   s!   ø€ Ø×Ñ×'Ò'Ü‰G‰NÕð (r'   c                ó®   — 	 t        | j                  j                  «       «       y # t        $ r Y y t        $ r}| j                  |«       Y d }~y d }~ww xY wr/   )r   r1   ÚcloseÚ
ValueErrorrC   rD   )r4   rG   s     r(   rT   z%AsyncAdapt_aiosqlite_connection.closeÓ   sL   € ð	*Ü�4×#Ñ#×)Ñ)Ó+Õ,øÜò 		ñ Üò 	*Ø×"Ñ" 5×)Ñ)ûð	*ús   ‚#& ¦	A±A¹AÁAc                óÖ   •— t        |t        «      rH|j                  d   j                  «       dv r)|j                  j                  |j                  d   «      |‚t        ‰| �  ||«       y )Nr   )úno active connectionúconnection closed)Ú
isinstancerU   rJ   ÚlowerÚsqliteÚOperationalErrorrM   Ú_handle_exception_no_connection)ÚclsÚdbapirG   rP   s      €r(   r]   z?AsyncAdapt_aiosqlite_connection._handle_exception_no_connectionã   s]   ø€ ô �eœZÔ(¨U¯Z©Z¸©]×-@Ñ-@Ó-Bð G
ñ .
ð —,‘,×/Ñ/°·
±
¸1±Ó>ÀEÐIä‰GÑ3°E¸5ÕAr'   c              ƒ  óT   K  — | j                   j                  «       ƒ d{  –—†  y7 Œ­w)z"Try to close connection gracefullyN)r1   rT   r3   s    r(   Ú_terminate_graceful_closez9AsyncAdapt_aiosqlite_connection._terminate_graceful_closeï   s   è ø€ à×Ñ×$Ñ$Ó&×&Ò&ús   ‚( &¡(c                óz   — 	 | j                   j                  } |«        y# t        $ r}t        d«      |‚d}~ww xY w)zTerminate the connectionz:terminate_force_close() not implemented by this DBAPI shimN)r1   ÚstopÚAttributeErrorÚNotImplementedError)r4   ÚmethÚaes      r(   Ú_terminate_force_closez6AsyncAdapt_aiosqlite_connection._terminate_force_closeó   sD   € ð
	Ø×#Ñ#×(Ñ(ˆDñ �Føô ò 	Ü%ØLóàðûð	ús   ‚   	:©5µ:)r;   r:   )r8   r:   r;   r<   )rJ   r   rK   r   r;   r<   ©r;   r<   )r_   r   rG   rC   r;   r	   )r#   r$   r%   r&   r    Ú_cursor_clsr+   Ú_ss_cursor_clsÚpropertyr2   ÚsetterrI   rN   rR   rT   Úclassmethodr]   ra   rh   Ú__classcell__©rP   s   @r(   r-   r-   £   s�   ø„ ð €Ià-€KØ3€Nàò;ó ð;ð ×Ñò*ó ð*ó**õõó*ð  ð	BØð	BØ )ð	Bà	ô	Bó ð	Bó'÷r'   r-   c                  ó0   ‡ — e Zd Zdˆ fd„Zdd„Zdd„Zˆ xZS )ÚAsyncAdapt_aiosqlite_dbapic                ó¨   •— t         ‰| �  ||¬«       || _        || _        d| _        t        |j                  d«      | _        | j                  «        y )N)Údbapi_moduleÚqmarkrc   )	rM   Ú__init__Ú	aiosqliter[   Ú
paramstyleÚhasattrÚ
ConnectionÚhas_stopÚ_init_dbapi_attributes)r4   rw   r[   rP   s      €r(   rv   z#AsyncAdapt_aiosqlite_dbapi.__init__  sJ   ø€ Ü‰Ñ˜°ÐÔ8Ø"ˆŒØˆŒØ!ˆŒÜ 	× 4Ñ 4°fÓ=ˆŒØ×#Ñ#Õ%r'   c           	     óô   — dD ]#  }t        | |t        | j                  |«      «       Œ% dD ]#  }t        | |t        | j                  |«      «       Œ% dD ]#  }t        | |t        | j                  |«      «       Œ% y )N)ÚDatabaseErrorÚErrorÚIntegrityErrorÚNotSupportedErrorr\   ÚProgrammingErrorÚsqlite_versionÚsqlite_version_info)ÚPARSE_COLNAMESÚPARSE_DECLTYPES)ÚBinary)ÚsetattrÚgetattrrw   r[   )r4   Únames     r(   r|   z1AsyncAdapt_aiosqlite_dbapi._init_dbapi_attributes  s|   € ð	
ò 
	?ˆDô �D˜$¤¨¯©¸Ó =Õ>ð
	?ð :ò 	<ˆDÜ�D˜$¤¨¯©°TÓ :Õ;ð	<ð  ò 	<ˆDÜ�D˜$¤¨¯©°TÓ :Õ;ñ	<r'   c                óð   — |j                  dd «      }|r	 ||i |¤Ž}nE | j                  j                  |i |¤Ž}t        |t        «      rd|_        nd|j                  _        t        | t        |«      «      S )NÚasync_creator_fnT)	Úpoprw   ÚconnectrY   r   ÚdaemonÚ_threadr-   r   )r4   ÚargrK   Ú
creator_fnr7   s        r(   rŽ   z"AsyncAdapt_aiosqlite_dbapi.connect  sv   € Ø—V‘VÐ.°Ó5ˆ
ÙÙ# SÐ/¨BÑ/‰Jà/˜Ÿ™×/Ñ/°Ð;¸Ñ;ˆJô ˜*¤fÔ-à$(�
Õ!ð -1�
×"Ñ"Ô)ä.¨t´V¸JÓ5GÓHÐHr'   )rw   r   r[   r   ri   )r‘   r   rK   r   r;   r-   )r#   r$   r%   rv   r|   rŽ   ro   rp   s   @r(   rr   rr     s   ø„ õ&ó<÷&Ir'   rr   c                  ó   — e Zd Zdd„Zy)Ú SQLiteExecutionContext_aiosqlitec                ó:   — | j                   j                  d¬«      S )NT)Úserver_side)Ú_dbapi_connectionÚcursorr3   s    r(   Úcreate_server_side_cursorz:SQLiteExecutionContext_aiosqlite.create_server_side_cursor1  s   € Ø×%Ñ%×,Ñ,¸Ð,Ó>Ð>r'   N)r;   r   )r#   r$   r%   r™   r!   r'   r(   r”   r”   0  s   „ ô?r'   r”   c                  ó˜   ‡ — e Zd ZdZdZdZdZdZeZ	d
ˆ fd„Z
edd„«       Zdd„Zedd„«       Z	 	 	 	 	 	 	 	 dˆ fd„Z	 	 	 	 dd„Zdd	„Zˆ xZS )ÚSQLiteDialect_aiosqliterw   Tc                óz   •— t        ‰| �  di |¤Ž | j                  r| j                  j                  sd| _        y y y )NFr!   )rM   rv   r_   r{   Úhas_terminate)r4   ÚkwargsrP   s     €r(   rv   z SQLiteDialect_aiosqlite.__init__@  s5   ø€ Ü‰ÑÑ"˜6Ò"Ø�:Š:˜dŸj™j×1Ò1Ø!&ˆDÕð 2ˆ:r'   c                ó>   — t        t        d«      t        d«      «      S )Nrw   Úsqlite3)rr   Ú
__import__)r^   s    r(   Úimport_dbapiz$SQLiteDialect_aiosqlite.import_dbapiE  s   € ä)Ü�{Ó#¤Z°	Ó%:ó
ð 	
r'   c                ó\   — t        |dd «      }t        j                  t        |dd «      «      S )Nrw   Ú__version__)r‰   r   Úparse_version_string)r4   r_   rw   s      r(   Úretrieve_dbapi_versionz.SQLiteDialect_aiosqlite.retrieve_dbapi_versionK  s1   € ô ˜E ;°Ó5ˆ	Ü×(Ñ(Ü�I˜}¨dÓ3ó
ð 	
r'   c                óÂ   — | j                  |«      rt        j                  S | j                  |t        j                  t        j                  «       t        j                  S r/   )Ú_is_url_file_dbr   ÚAsyncAdaptedQueuePoolÚ _warn_memory_mode_pool_selectionÚ
StaticPool)r^   Úurls     r(   Úget_pool_classz&SQLiteDialect_aiosqlite.get_pool_classS  sG   € à×Ñ˜sÔ#Ü×-Ñ-Ð-à×0Ñ0Ø”T—_‘_¤d×&@Ñ&@ôô —?‘?Ð"r'   c                óà   •— t        d| j                  «      | _        t        || j                  j                  «      r"t	        |«      j                  «       }d|v sd|v ryt        ‰| �  |||«      S )Nr   rW   rX   T)r   r_   rY   r\   r0   rZ   rM   Úis_disconnect)r4   Úer7   r˜   Ú	err_lowerrP   s        €r(   r¯   z%SQLiteDialect_aiosqlite.is_disconnect]  sa   ø€ ô ˜-¨¯©Ó4ˆŒ
Ü�a˜Ÿ™×4Ñ4Ô5Ü˜A›Ÿ™›ˆIà&¨)Ñ3Ø&¨)Ñ3àä‰wÑ$ Q¨
°FÓ;Ð;r'   c                ó   — |j                   S r/   )r1   )r4   r7   s     r(   Úget_driver_connectionz-SQLiteDialect_aiosqlite.get_driver_connectionn  s   € ð ×%Ñ%Ð%r'   c                ó$   — |j                  «        y r/   )Ú	terminate)r4   Údbapi_connections     r(   Údo_terminatez$SQLiteDialect_aiosqlite.do_terminates  s   € Ø×"Ñ"Õ$r'   )rž   r   )r;   rr   )r_   r   r;   zutil.VersionInfo)r¬   r   r;   ztype[pool.Pool])r°   zDBAPIModule.Errorr7   z7Optional[Union[PoolProxiedConnection, DBAPIConnection]]r˜   zOptional[DBAPICursor]r;   Úbool)r7   r   r;   r   )r¶   r   r;   r<   )r#   r$   r%   ÚdriverÚsupports_statement_cacheÚis_asyncr�   Úsupports_server_side_cursorsr”   Úexecution_ctx_clsrv   rn   r¢   r¦   r­   r¯   r³   r·   ro   rp   s   @r(   r›   r›   5  sœ   ø„ Ø€FØ#Ðà€HØ€Mà#'Ð à8Ðõ'ð
 ò
ó ð
ó

ð ò#ó ð#ð<àð<ð Lð<ð &ð	<ð
 
õ<ð"&Ø)ð&à	ó&÷
%r'   r›   )0Ú__doc__Ú
__future__r   r>   Ú	functoolsr   Ú	threadingr   Útypesr   Útypingr   r   r	   r
   r   r   Úbaser   Úpysqliter   Ú r   r   Úconnectors.asyncior   r   r   r   r   Úutil.concurrencyr   r   Úengine.interfacesr   r   r   Ú
engine.urlr   Ú	pool.baser   r    r+   r-   rr   r”   r›   Údialectr!   r'   r(   ú<module>rÍ      sÁ   ðñoõb #ã Ý Ý Ý Ý Ý Ý Ý Ý  Ý å (Ý ,Ý Ý Ý =Ý 9Ý 9Ý <Ý 6Ý &áÝ<Ý4Ý0Ý0Ý!Ý2ôÐ"9ô ôÐ%?ô ô\ØÐ5ô\ô~+IÐ!8ô +Iô\?Ð'=ô ?ô
?%Ð4ô ?%ðD "�r'   