Ë
    V.jÅ1  ã                   ó  — d 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  G d„ d«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ d«      Z G d„ de«      Z G d„ de	«      ZeZy)aZ
  

.. 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)
-------------------------------------------------------------------------

Similarly to pysqlite, aiosqlite does not support SAVEPOINT feature.

The solution is similar to :ref:`pysqlite_serializable`. This is achieved by the event listeners in async::

    from sqlalchemy import create_engine, event
    from sqlalchemy.ext.asyncio import create_async_engine

    engine = create_async_engine("sqlite+aiosqlite:///myfile.db")

    @event.listens_for(engine.sync_engine, "connect")
    def do_connect(dbapi_connection, connection_record):
        # disable aiosqlite's emitting of the BEGIN statement entirely.
        # also stops it from emitting COMMIT before any DDL.
        dbapi_connection.isolation_level = None

    @event.listens_for(engine.sync_engine, "begin")
    def do_begin(conn):
        # emit our own BEGIN
        conn.exec_driver_sql("BEGIN")

.. warning:: When using the above recipe, it is advised to not use the
   :paramref:`.Connection.execution_options.isolation_level` setting on
   :class:`_engine.Connection` and :func:`_sa.create_engine`
   with the SQLite driver,
   as this function necessarily will also alter the ".isolation_level" setting.

é    N)Údeque)Úpartialé   )ÚSQLiteExecutionContext)ÚSQLiteDialect_pysqliteé   )Úpool)Úutil)ÚAdaptedConnection)Úawait_fallback)Ú
await_onlyc                   óN   — e Zd ZdZdZd„ Zd„ Zdd„Zd„ Zd„ Z	d	„ Z
d
„ Zdd„Zd„ Zy)ÚAsyncAdapt_aiosqlite_cursor)Ú_adapt_connectionÚ_connectionÚdescriptionÚawait_Ú_rowsÚ	arraysizeÚrowcountÚ	lastrowidFc                 óž   — || _         |j                  | _        |j                  | _        d| _        d| _        d | _        t        «       | _        y )Nr   éÿÿÿÿ)r   r   r   r   r   r   r   r   )ÚselfÚadapt_connections     úfC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\site-packages\sqlalchemy/dialects/sqlite/aiosqlite.pyÚ__init__z$AsyncAdapt_aiosqlite_cursor.__init__n   sD   € Ø!1ˆÔØ+×7Ñ7ˆÔØ&×-Ñ-ˆŒØˆŒØˆŒØˆÔÜ“Wˆ�
ó    c                 ó8   — | j                   j                  «        y ©N)r   Úclear©r   s    r   Úclosez!AsyncAdapt_aiosqlite_cursor.closew   s   € Ø�
‰
×ÑÕr   Nc                 óÄ  — 	 | j                  | j                  j                  «       «      }|€!| j                  |j                  |«      «       n!| j                  |j                  ||«      «       |j                  rY|j                  | _        dx| _        | _        | j                  sWt        | j                  |j                  «       «      «      | _
        n)d | _        |j
                  | _        |j                  | _        | j                  s | j                  |j                  «       «       y || _        y # t        $ r%}| j                  j                  |«       Y d }~y d }~ww xY w)Nr   )r   r   ÚcursorÚexecuter   r   r   Úserver_sider   Úfetchallr   r#   Ú_cursorÚ	Exceptionr   Ú_handle_exception)r   Ú	operationÚ
parametersr)   Úerrors        r   r&   z#AsyncAdapt_aiosqlite_cursor.executez   s  € ð	<Ø—k‘k $×"2Ñ"2×"9Ñ"9Ó";Ó<ˆGàÐ!Ø—‘˜GŸO™O¨IÓ6Õ7à—‘˜GŸO™O¨I°zÓBÔCà×"Ò"Ø#*×#6Ñ#6�Ô Ø13Ð3�” ¤à×'Ò'Ü!& t§{¡{°7×3CÑ3CÓ3EÓ'FÓ!G�D•Jà#'�Ô Ø!(×!2Ñ!2�”Ø '× 0Ñ 0�”à×#Ò#Ø—‘˜GŸM™M›OÕ,à&�•øÜò 	<Ø×"Ñ"×4Ñ4°U×;Ñ;ûð	<ús   ‚D&D1 Ä)D1 Ä1	EÄ:EÅEc                 óŒ  — 	 | j                  | j                  j                  «       «      }| j                  |j                  ||«      «       d | _        |j
                  | _        |j                  | _        | j                  |j                  «       «       y # t        $ r%}| j                  j                  |«       Y d }~y d }~ww xY wr    )r   r   r%   Úexecutemanyr   r   r   r#   r*   r   r+   )r   r,   Úseq_of_parametersr)   r.   s        r   r0   z'AsyncAdapt_aiosqlite_cursor.executemany•   s™   € ð	<Ø—k‘k $×"2Ñ"2×"9Ñ"9Ó";Ó<ˆGØ�K‰K˜×+Ñ+¨IÐ7HÓIÔJØ#ˆDÔØ$×.Ñ.ˆDŒNØ#×,Ñ,ˆDŒMØ�K‰K˜Ÿ™›Õ(øÜò 	<Ø×"Ñ"×4Ñ4°U×;Ñ;ûð	<ús   ‚BB Â	CÂB>Â>Cc                  ó   — y r    © )r   Ú
inputsizess     r   Úsetinputsizesz)AsyncAdapt_aiosqlite_cursor.setinputsizes    s   € Ør   c              #   óx   K  — | j                   r*| j                   j                  «       –— | j                   rŒ)y y ­wr    ©r   Úpopleftr"   s    r   Ú__iter__z$AsyncAdapt_aiosqlite_cursor.__iter__£   s)   è ø€ Ø�jŠjØ—*‘*×$Ñ$Ó&Ò&ð �j�jùs   ‚5:¸:c                 óP   — | j                   r| j                   j                  «       S y r    r7   r"   s    r   Úfetchonez$AsyncAdapt_aiosqlite_cursor.fetchone§   s   € Ø�:Š:Ø—:‘:×%Ñ%Ó'Ð'àr   c                 ó´   — |€| j                   }| j                  }t        t        |t	        |«      «      «      D �cg c]  }|j                  «       ‘Œ c}S c c}w r    )r   r   ÚrangeÚminÚlenr8   )r   ÚsizeÚrrÚ_s       r   Ú	fetchmanyz%AsyncAdapt_aiosqlite_cursor.fetchmany­   sI   € Øˆ<Ø—>‘>ˆDà�Z‰ZˆÜ&+¬C°´c¸"³gÓ,>Ô&?Ó@Ñ&? �—
‘
•Ð&?Ñ@Ð@ùÒ@s   »Ac                 ód   — t        | j                  «      }| j                  j                  «        |S r    )Úlistr   r!   )r   Úretvals     r   r(   z$AsyncAdapt_aiosqlite_cursor.fetchall´   s%   € Ü�d—j‘jÓ!ˆØ�
‰
×ÑÔØˆr   r    )Ú__name__Ú
__module__Ú__qualname__Ú	__slots__r'   r   r#   r&   r0   r5   r9   r;   rC   r(   r3   r   r   r   r   ]   s>   „ ð	€Ið €Kòòó<ò6	<òò'òóAór   r   c                   ó@   ‡ — e Zd ZdZdZˆ fd„Zd„ Zd„ Zdd„Zd„ Z	ˆ xZ
S )	ÚAsyncAdapt_aiosqlite_ss_cursorr)   Tc                 ó2   •— t        ‰| �  |i |¤Ž d | _        y r    )Úsuperr   r)   )r   ÚargÚkwÚ	__class__s      €r   r   z'AsyncAdapt_aiosqlite_ss_cursor.__init__Á   s   ø€ Ü‰Ñ˜#Ð$ Ò$Øˆ�r   c                 ó~   — | j                   �1| j                  | j                   j                  «       «       d | _         y y r    )r)   r   r#   r"   s    r   r#   z$AsyncAdapt_aiosqlite_ss_cursor.closeÅ   s1   € Ø�<‰<Ð#Ø�K‰K˜Ÿ™×*Ñ*Ó,Ô-ØˆD�Lð $r   c                 óT   — | j                  | j                  j                  «       «      S r    )r   r)   r;   r"   s    r   r;   z'AsyncAdapt_aiosqlite_ss_cursor.fetchoneÊ   ó   € Ø�{‰{˜4Ÿ<™<×0Ñ0Ó2Ó3Ð3r   c                 ót   — |€| j                   }| j                  | j                  j                  |¬«      «      S )N)r@   )r   r   r)   rC   )r   r@   s     r   rC   z(AsyncAdapt_aiosqlite_ss_cursor.fetchmanyÍ   s1   € Øˆ<Ø—>‘>ˆDØ�{‰{˜4Ÿ<™<×1Ñ1°tÐ1Ó<Ó=Ð=r   c                 óT   — | j                  | j                  j                  «       «      S r    )r   r)   r(   r"   s    r   r(   z'AsyncAdapt_aiosqlite_ss_cursor.fetchallÒ   rT   r   r    )rG   rH   rI   rJ   r'   r   r#   r;   rC   r(   Ú__classcell__©rQ   s   @r   rL   rL   º   s(   ø„ ð €Ià€Kôò ò
4ó>ö
4r   rL   c                   ó†   — e Zd Z ee«      ZdZd„ Zed„ «       Z	e	j                  d„ «       Z	d„ Zdd„Zd„ Zd„ Zd	„ Zd
„ Zd„ Zy)ÚAsyncAdapt_aiosqlite_connection)Údbapic                 ó    — || _         || _        y r    )r[   r   )r   r[   Ú
connections      r   r   z(AsyncAdapt_aiosqlite_connection.__init__Ú   s   € ØˆŒ
Ø%ˆÕr   c                 ó.   — | j                   j                  S r    )r   Úisolation_levelr"   s    r   r_   z/AsyncAdapt_aiosqlite_connection.isolation_levelÞ   s   € à×Ñ×/Ñ/Ð/r   c                 óN  — d„ }t        || j                  j                  |«      }t        j                  «       j                  «       }| j                  j                  j                  ||f«       	 | j                  |«      S # t        $ r}| j                  |«       Y d }~y d }~ww xY w)Nc                 ó   — || _         y r    )r_   )r]   Úvalues     r   Úset_isoz@AsyncAdapt_aiosqlite_connection.isolation_level.<locals>.set_isoé   s
   € Ø).ˆJÕ&r   )r   r   Ú_connÚasyncioÚget_event_loopÚcreate_futureÚ_txÚ
put_nowaitr   r*   r+   )r   rb   rc   ÚfunctionÚfuturer.   s         r   r_   z/AsyncAdapt_aiosqlite_connection.isolation_levelâ   sŽ   € ò	/ô ˜7 D×$4Ñ$4×$:Ñ$:¸EÓBˆÜ×'Ñ'Ó)×7Ñ7Ó9ˆà×Ñ×Ñ×'Ñ'¨°Ð(:Ô;ð	*Ø—;‘;˜vÓ&Ð&øÜò 	*Ø×"Ñ" 5×)Ñ)ûð	*ús   Á/B  Â 	B$Â	BÂB$c                 óª   — 	 | j                   | j                  j                  |i |¤Ž«       y # t        $ r}| j	                  |«       Y d }~y d }~ww xY wr    )r   r   Úcreate_functionr*   r+   )r   ÚargsrP   r.   s       r   rm   z/AsyncAdapt_aiosqlite_connection.create_functionö   sM   € ð	*Ø�K‰KÐ8˜×(Ñ(×8Ñ8¸$ÐEÀ"ÑEÕFøÜò 	*Ø×"Ñ" 5×)Ñ)ûð	*ús   ‚+. ®	A·AÁAc                 ó2   — |rt        | «      S t        | «      S r    )rL   r   )r   r'   s     r   r%   z&AsyncAdapt_aiosqlite_connection.cursorü   s   € ÙÜ1°$Ó7Ð7ä.¨tÓ4Ð4r   c                 óX   — | j                   | j                  j                  |i |¤Ž«      S r    )r   r   r&   )r   rn   rP   s      r   r&   z'AsyncAdapt_aiosqlite_connection.execute  s*   € Ø�{‰{Ð3˜4×+Ñ+×3Ñ3°TÐ@¸RÑ@ÓAÐAr   c                 ó¦   — 	 | j                  | j                  j                  «       «       y # t        $ r}| j	                  |«       Y d }~y d }~ww xY wr    )r   r   Úrollbackr*   r+   ©r   r.   s     r   rr   z(AsyncAdapt_aiosqlite_connection.rollback  sC   € ð	*Ø�K‰K˜×(Ñ(×1Ñ1Ó3Õ4øÜò 	*Ø×"Ñ" 5×)Ñ)ûð	*úó   ‚), ¬	AµAÁAc                 ó¦   — 	 | j                  | j                  j                  «       «       y # t        $ r}| j	                  |«       Y d }~y d }~ww xY wr    )r   r   Úcommitr*   r+   rs   s     r   rv   z&AsyncAdapt_aiosqlite_connection.commit  sC   € ð	*Ø�K‰K˜×(Ñ(×/Ñ/Ó1Õ2øÜò 	*Ø×"Ñ" 5×)Ñ)ûð	*úrt   c                 óº   — 	 | j                  | j                  j                  «       «       y # t        $ r Y y t        $ r}| j                  |«       Y d }~y d }~ww xY wr    )r   r   r#   Ú
ValueErrorr*   r+   rs   s     r   r#   z%AsyncAdapt_aiosqlite_connection.close  sP   € ð	*Ø�K‰K˜×(Ñ(×.Ñ.Ó0Õ1øÜò 		ñ Üò 	*Ø×"Ñ" 5×)Ñ)ûð	*ús   ‚), ¬	A·A¿AÁAc                 ó–   — t        |t        «      r8|j                  d   dk(  r&| j                  j                  j                  d«      |‚|‚)Nr   úno active connection)Ú
isinstancerx   rn   r[   ÚsqliteÚOperationalErrorrs   s     r   r+   z1AsyncAdapt_aiosqlite_connection._handle_exception!  sG   € ä�uœjÔ)Ø—
‘
˜1‘Ð!7Ò7à—*‘*×#Ñ#×4Ñ4Ø&óàðð ˆKr   N)F)rG   rH   rI   Ústaticmethodr   r   rJ   r   Úpropertyr_   Úsetterrm   r%   r&   rr   rv   r#   r+   r3   r   r   rZ   rZ   Ö   sh   „ Ù˜*Ó%€FØ€Iò&ð ñ0ó ð0ð ×Ññ*ó ð*ò&*ó5òBò*ò*ò*ó 	r   rZ   c                   ó    — e Zd ZdZ ee«      Zy)Ú'AsyncAdaptFallback_aiosqlite_connectionr3   N)rG   rH   rI   rJ   r~   r   r   r3   r   r   r‚   r‚   -  s   „ Ø€Iá˜.Ó)�Fr   r‚   c                   ó   — e Zd Zd„ Zd„ Zd„ Zy)ÚAsyncAdapt_aiosqlite_dbapic                 óN   — || _         || _        d| _        | j                  «        y )NÚqmark)Ú	aiosqliter|   Ú
paramstyleÚ_init_dbapi_attributes)r   r‡   r|   s      r   r   z#AsyncAdapt_aiosqlite_dbapi.__init__4  s#   € Ø"ˆŒØˆŒØ!ˆŒØ×#Ñ#Õ%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Úgetattrr‡   r|   )r   Únames     r   r‰   z1AsyncAdapt_aiosqlite_dbapi._init_dbapi_attributes:  sm   € ó	
ˆDô �D˜$¤¨¯©¸Ó =Õ>ð	
ó :ˆDÜ�D˜$¤¨¯©°TÓ :Õ;ð :ó  ˆDÜ�D˜$¤¨¯©°TÓ :Õ;ñ  r   c                 ó$  — |j                  dd«      }|j                  dd «      }|r	 ||i |¤Ž}n# | j                  j                  |i |¤Ž}d|_        t	        j
                  |«      rt        | t        |«      «      S t        | t        |«      «      S )NÚasync_fallbackFÚasync_creator_fnT)
Úpopr‡   ÚconnectÚdaemonr
   Úasboolr‚   r   rZ   r   )r   rO   rP   r™   Ú
creator_fnr]   s         r   rœ   z"AsyncAdapt_aiosqlite_dbapi.connectM  s—   € ØŸ™Ð 0°%Ó8ˆà—V‘VÐ.°Ó5ˆ
ÙÙ# SÐ/¨BÑ/‰Jà/˜Ÿ™×/Ñ/°Ð;¸Ñ;ˆJà $ˆJÔä�;‰;�~Ô&Ü:ØÜ˜zÓ*óð ô
 3ØÜ˜:Ó&óð r   N)rG   rH   rI   r   r‰   rœ   r3   r   r   r„   r„   3  s   „ ò&ò<ó&r   r„   c                   ó   — e Zd Zd„ Zy)Ú SQLiteExecutionContext_aiosqlitec                 ó:   — | j                   j                  d¬«      S )NT)r'   )Ú_dbapi_connectionr%   r"   s    r   Úcreate_server_side_cursorz:SQLiteExecutionContext_aiosqlite.create_server_side_cursore  s   € Ø×%Ñ%×,Ñ,¸Ð,Ó>Ð>r   N)rG   rH   rI   r¤   r3   r   r   r¡   r¡   d  s   „ ó?r   r¡   c                   óX   ‡ — e Zd ZdZdZdZdZeZe	d„ «       Z
e	d„ «       Zˆ fd„Zd„ Zˆ xZS )ÚSQLiteDialect_aiosqliter‡   Tc                 ó>   — t        t        d«      t        d«      «      S )Nr‡   Úsqlite3)r„   Ú
__import__)Úclss    r   Úimport_dbapiz$SQLiteDialect_aiosqlite.import_dbapis  s   € ä)Ü�{Ó#¤Z°	Ó%:ó
ð 	
r   c                 ód   — | j                  |«      rt        j                  S t        j                  S r    )Ú_is_url_file_dbr	   ÚNullPoolÚ
StaticPool)rª   Úurls     r   Úget_pool_classz&SQLiteDialect_aiosqlite.get_pool_classy  s$   € à×Ñ˜sÔ#Ü—=‘=Ð ä—?‘?Ð"r   c                 ó‚   •— t        || j                  j                  «      rdt        |«      v ryt        ‰| �  |||«      S )Nrz   T)r{   r[   r}   ÚstrrN   Úis_disconnect)r   Úer]   r%   rQ   s       €r   r´   z%SQLiteDialect_aiosqlite.is_disconnect€  s=   ø€ ÜØˆt�z‰z×*Ñ*ô
à$¬¨A«Ñ.Øä‰wÑ$ Q¨
°FÓ;Ð;r   c                 ó   — |j                   S r    )r   )r   r]   s     r   Úget_driver_connectionz-SQLiteDialect_aiosqlite.get_driver_connectionˆ  s   € Ø×%Ñ%Ð%r   )rG   rH   rI   ÚdriverÚsupports_statement_cacheÚis_asyncÚsupports_server_side_cursorsr¡   Úexecution_ctx_clsÚclassmethodr«   r±   r´   r·   rW   rX   s   @r   r¦   r¦   i  sO   ø„ Ø€FØ#Ðà€Hà#'Ð à8Ðàñ
ó ð
ð
 ñ#ó ð#ô<ö&r   r¦   )Ú__doc__re   Úcollectionsr   Ú	functoolsr   Úbaser   Úpysqliter   Ú r	   r
   Úenginer   Úutil.concurrencyr   r   r   rL   rZ   r‚   r„   r¡   r¦   Údialectr3   r   r   Ú<module>rÇ      s�   ðñDóL Ý Ý å (Ý ,Ý Ý Ý 'Ý .Ý *÷Zñ Zôz4Ð%@ô 4ô8TÐ&7ô Tôn*Ð.Mô *÷.ñ .ôb?Ð'=ô ?ô
 &Ð4ô  &ðF "�r   