
    `?iZ9                    .   S r SSKJr  SSKrSSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSK
Jr  SS	K
Jr  SS
K
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSKJ!r!  \(       a<  SSKJ"r"  SSKJ#r#  SSK$J%r%  SSK$J&r&  SSK$J'r'  SSK$J(r(  SS K$J)r)  SS!K$J*r*  SS"K+J,r,  SS#K-J.r.   " S$ S%5      r/ " S& S'\/5      r0 " S( S)\5      r1 " S* S+\15      r2 " S, S-\5      r3 " S. S/\5      r4 " S0 S1\5      r5\5r6g)2a	  

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

    )annotationsN)deque)partial)
ModuleType)Any)cast)Deque)Iterator)NoReturn)Optional)Sequence)TYPE_CHECKING)Union   )SQLiteExecutionContext)SQLiteDialect_pysqlite   )pool)util)AsyncAdapt_dbapi_module)AdaptedConnection)await_fallback)
await_only)AsyncIODBAPIConnection)AsyncIODBAPICursor)_DBAPICursorDescription)_DBAPIMultiExecuteParams)_DBAPISingleExecuteParams)DBAPIConnection)DBAPICursor)DBAPIModule)URL)PoolProxiedConnectionc                      \ rS rSrSrSrSS jrSS jrSS jr S     SS jjr	      SS	 jr
SS
 jrSS jrSS jrSSS jjrSS jrSrg)AsyncAdapt_aiosqlite_cursorv   )_adapt_connection_connectiondescriptionawait__rows	arraysizerowcount	lastrowidFc                    Xl         UR                  U l        UR                  U l        SU l        SU l        S U l        [        5       U l        g )Nr   )r'   r(   r*   r,   r-   r)   r   r+   )selfadapt_connections     h/var/www/html/livechat/backend/venv/lib/python3.13/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py__init__$AsyncAdapt_aiosqlite_cursor.__init__   sB    !1+77&-->B!&
    c                   #    g 7fN r1   s    r3   _async_soft_close-AsyncAdapt_aiosqlite_cursor._async_soft_close   s     s   c                8    U R                   R                  5         g r8   )r+   clearr:   s    r3   close!AsyncAdapt_aiosqlite_cursor.close   s    

r6   Nc                    U R                  U R                  R                  5       5      nUc!  U R                  UR                  U5      5        O U R                  UR                  X5      5        UR                  (       a^  UR                  U l        S=U l        U l        U R                  (       d-  [        U R                  UR                  5       5      5      U l
        O)S U l        UR
                  U l        UR                  U l        U R                  (       d   U R                  UR                  5       5        g X0l        g ! [         a%  nU R                  R                  U5         S nAg S nAff = f)Nr0   )r*   r(   cursorexecuter)   r.   r-   server_sider   fetchallr+   r?   _cursor	Exceptionr'   _handle_exception)r1   	operation
parametersrF   errors        r3   rC   #AsyncAdapt_aiosqlite_cursor.execute   s
   	<*.++d6F6F6M6M6O*PG!GOOI67GOOIBC""#*#6#6 133''!&t{{73C3C3E'F!GDJ#' !(!2!2 ' 0 0##GMMO,& 	<""44U;;	<s   D5D? 8D? ?
E.	E))E.c                    U R                  U R                  R                  5       5      nU R                  UR                  X5      5        S U l        UR
                  U l        UR                  U l        U R                  UR                  5       5        g ! [         a%  nU R                  R                  U5         S nAg S nAff = fr8   )r*   r(   rB   executemanyr)   r.   r-   r?   rG   r'   rH   )r1   rI   seq_of_parametersrF   rK   s        r3   rN   'AsyncAdapt_aiosqlite_cursor.executemany   s    
	<*.++d6F6F6M6M6O*PGKK++IIJ#D$..DN#,,DMKK( 	<""44U;;	<s   BB 
CB>>Cc                    g r8   r9   )r1   
inputsizess     r3   setinputsizes)AsyncAdapt_aiosqlite_cursor.setinputsizes   s    r6   c              #     #    U R                   (       a0  U R                   R                  5       v   U R                   (       a  M/  g g 7fr8   r+   popleftr:   s    r3   __iter__$AsyncAdapt_aiosqlite_cursor.__iter__   s*     jj**$$&& jjjs   ?AAc                Z    U R                   (       a  U R                   R                  5       $ g r8   rV   r:   s    r3   fetchone$AsyncAdapt_aiosqlite_cursor.fetchone   s    ::::%%''r6   c                    Uc  U R                   nU R                  n[        [        U[	        U5      5      5       Vs/ s H  o2R                  5       PM     sn$ s  snf r8   )r,   r+   rangeminlenrW   )r1   sizerr_s       r3   	fetchmany%AsyncAdapt_aiosqlite_cursor.fetchmany   sG    <>>DZZ&+Cc"g,>&?@&?

&?@@@s   Ac                d    [        U R                  5      nU R                  R                  5         U$ r8   )listr+   r>   )r1   retvals     r3   rE   $AsyncAdapt_aiosqlite_cursor.fetchall   s%    djj!

r6   )	r'   r(   rF   r+   r,   r*   r)   r.   r-   )r2   AsyncAdapt_aiosqlite_connectionreturnNoner8   )rI   r   rJ   z#Optional[_DBAPISingleExecuteParams]rl   r   )rI   r   rO   r   rl   r   )rR   r   rl   rm   )rl   zIterator[Any]rl   zOptional[Any]ra   zOptional[int]rl   Sequence[Any]rl   rp   )__name__
__module____qualname____firstlineno__	__slots__rD   r4   r;   r?   rC   rN   rS   rX   r[   rd   rE   __static_attributes__r9   r6   r3   r%   r%   v   s    	I K) ;?<< 8< 
	<@<< 4< 
	<'Ar6   r%   c                  `   ^  \ rS rSrSrSrS
U 4S jjrSS jrSS jrSSS jjr	SS jr
S	rU =r$ )AsyncAdapt_aiosqlite_ss_cursor   rF   Tc                4   > [         TU ]  " U0 UD6  S U l        g r8   )superr4   rF   )r1   argkw	__class__s      r3   r4   'AsyncAdapt_aiosqlite_ss_cursor.__init__   s    #$$59r6   c                    U R                   b1  U R                  U R                   R                  5       5        S U l         g g r8   )rF   r*   r?   r:   s    r3   r?   $AsyncAdapt_aiosqlite_ss_cursor.close   s1    <<#KK**,-DL $r6   c                r    U R                   c   eU R                  U R                   R                  5       5      $ r8   )rF   r*   r[   r:   s    r3   r[   'AsyncAdapt_aiosqlite_ss_cursor.fetchone   .    ||'''{{4<<00233r6   c                    U R                   c   eUc  U R                  nU R                  U R                   R                  US95      $ )N)ra   )rF   r,   r*   rd   )r1   ra   s     r3   rd   (AsyncAdapt_aiosqlite_ss_cursor.fetchmany   sA    ||'''<>>D{{4<<11t1<==r6   c                r    U R                   c   eU R                  U R                   R                  5       5      $ r8   )rF   r*   rE   r:   s    r3   rE   'AsyncAdapt_aiosqlite_ss_cursor.fetchall   r   r6   )rF   )r}   r   r~   r   rl   rm   rk   rn   r8   ro   rq   )rr   rs   rt   ru   rv   rD   r4   r?   r[   rd   rE   rw   __classcell__r   s   @r3   ry   ry      s-     IK: 
4>4 4r6   ry   c                      \ rS rSr\" \5      rSrSS jr\	SS j5       r
\
R                  SS j5       r
SS jrSSS jjrSS jrSS	 jrSS
 jrSS jrSS jrSrg)rj      dbapic                    Xl         X l        g r8   )r   r(   )r1   r   
connections      r3   r4   (AsyncAdapt_aiosqlite_connection.__init__  s    
%r6   c                J    [        [        U R                  R                  5      $ r8   )r   strr(   isolation_levelr:   s    r3   r   /AsyncAdapt_aiosqlite_connection.isolation_level  s    C))99::r6   c                `         SS jn[        X R                  R                  U5      n[        R                  " 5       R                  5       nU R                  R                  R                  XC45         U R                  U5        g ! [         a  nU R                  U5         S nAg S nAff = f)Nc                    Xl         g r8   )r   )r   values     r3   set_iso@AsyncAdapt_aiosqlite_connection.isolation_level.<locals>.set_iso  s
     */&r6   )r   rj   r   Optional[str]rl   rm   )r   r(   _connasyncioget_event_loopcreate_future_tx
put_nowaitr*   rG   rH   )r1   r   r   functionfuturerK   s         r3   r   r   
  s    	/7	/@M	/	/
 7$4$4$:$:EB'')779''(:;	*KK 	*""5))	*s   6B 
B-B((B-c                     U R                  U R                  R                  " U0 UD65        g ! [         a  nU R	                  U5         S nAg S nAff = fr8   )r*   r(   create_functionrG   rH   )r1   argsr~   rK   s       r3   r   /AsyncAdapt_aiosqlite_connection.create_function   sJ    	*KK((88$E"EF 	*""5))	*s   +. 
AAAc                <    U(       a  [        U 5      $ [        U 5      $ r8   )ry   r%   )r1   rD   s     r3   rB   &AsyncAdapt_aiosqlite_connection.cursor&  s    1$77.t44r6   c                X    U R                  U R                  R                  " U0 UD65      $ r8   )r*   r(   rC   )r1   r   r~   s      r3   rC   'AsyncAdapt_aiosqlite_connection.execute,  s'    {{4++33T@R@AAr6   c                     U R                  U R                  R                  5       5        g ! [         a  nU R	                  U5         S nAg S nAff = fr8   )r*   r(   rollbackrG   rH   r1   rK   s     r3   r   (AsyncAdapt_aiosqlite_connection.rollback/  sC    	*KK((1134 	*""5))	*   ), 
AAAc                     U R                  U R                  R                  5       5        g ! [         a  nU R	                  U5         S nAg S nAff = fr8   )r*   r(   commitrG   rH   r   s     r3   r   &AsyncAdapt_aiosqlite_connection.commit5  sC    	*KK((//12 	*""5))	*r   c                     U R                  U R                  R                  5       5        g ! [         a     g [         a  nU R                  U5         S nAg S nAff = fr8   )r*   r(   r?   
ValueErrorrG   rH   r   s     r3   r?   %AsyncAdapt_aiosqlite_connection.close;  sP    	*KK((..01 		  	*""5))	*s   ), 
A	AAAc                    [        U[        5      (       a9  UR                  S   S:X  a&  U R                  R                  R                  S5      UeUe)Nr   no active connection)
isinstancer   r   r   sqliteOperationalErrorr   s     r3   rH   1AsyncAdapt_aiosqlite_connection._handle_exceptionK  sJ    uj))

1!77**##44& Kr6   )r(   r   N)r   r   r   r   rl   rm   )rl   r   )r   r   rl   rm   )r   r   r~   r   rl   rm   )F)rD   boolrl   r%   )r   r   r~   r   rl   r   rk   )rK   rG   rl   r   )rr   rs   rt   ru   staticmethodr   r*   rv   r4   propertyr   setterr   rB   rC   r   r   r?   rH   rw   r9   r6   r3   rj   rj      sh    *%FI& ; ; * ***5B*** 	r6   rj   c                  (    \ rS rSrSr\" \5      rSrg)'AsyncAdaptFallback_aiosqlite_connectioniW  r9   N)	rr   rs   rt   ru   rv   r   r   r*   rw   r9   r6   r3   r   r   W  s    I.)Fr6   r   c                  2    \ rS rSrSS jrSS jrS	S jrSrg)
AsyncAdapt_aiosqlite_dbapii]  c                J    Xl         X l        SU l        U R                  5         g )Nqmark)	aiosqliter   
paramstyle_init_dbapi_attributes)r1   r   r   s      r3   r4   #AsyncAdapt_aiosqlite_dbapi.__init__^  s    "!##%r6   c           	         S H#  n[        X[        U R                  U5      5        M%     S H#  n[        X[        U R                  U5      5        M%     S H#  n[        X[        U R                  U5      5        M%     g )N)DatabaseErrorErrorIntegrityErrorNotSupportedErrorr   ProgrammingErrorsqlite_versionsqlite_version_info)PARSE_COLNAMESPARSE_DECLTYPES)Binary)setattrgetattrr   r   )r1   names     r3   r   1AsyncAdapt_aiosqlite_dbapi._init_dbapi_attributesd  sg    	
D D =>	
 :DDT :; :  DDT :;  r6   c                :   UR                  SS5      nUR                  SS 5      nU(       a	  U" U0 UD6nO#U R                  R                  " U0 UD6nSUl        [        R
                  " U5      (       a  [        U [        U5      5      $ [        U [        U5      5      $ )Nasync_fallbackFasync_creator_fnT)
popr   connectdaemonr   asboolr   r   rj   r   )r1   r}   r~   r   
creator_fnr   s         r3   r   "AsyncAdapt_aiosqlite_dbapi.connectw  s     0%8VV.5
#S/B/J//;;J $J;;~&&:z* 
 3:& r6   )r   r   r   N)r   r   r   r   rk   )r}   r   r~   r   rl   rj   )rr   rs   rt   ru   r4   r   r   rw   r9   r6   r3   r   r   ]  s    &<&r6   r   c                      \ rS rSrSS jrSrg) SQLiteExecutionContext_aiosqlitei  c                4    U R                   R                  SS9$ )NT)rD   )_dbapi_connectionrB   r:   s    r3   create_server_side_cursor:SQLiteExecutionContext_aiosqlite.create_server_side_cursor  s    %%,,,>>r6   r9   N)rl   r    )rr   rs   rt   ru   r   rw   r9   r6   r3   r   r     s    ?r6   r   c                     ^  \ rS rSrSrSrSrSr\r	\
S	S j5       r\
S
S j5       r        SU 4S jjr    SS jrSrU =r$ )SQLiteDialect_aiosqlitei  r   Tc                >    [        [        S5      [        S5      5      $ )Nr   sqlite3)r   
__import__)clss    r3   import_dbapi$SQLiteDialect_aiosqlite.import_dbapi  s    ){#Z	%:
 	
r6   c                n    U R                  U5      (       a  [        R                  $ [        R                  $ r8   )_is_url_file_dbr   AsyncAdaptedQueuePool
StaticPool)r   urls     r3   get_pool_class&SQLiteDialect_aiosqlite.get_pool_class  s)    s##---??"r6   c                   > [        SU R                  5      U l        [        XR                  R                  5      (       a  S[	        U5      ;   a  g[
        TU ]  XU5      $ )Nr!   r   T)r   r   r   r   r   r|   is_disconnect)r1   er   rB   r   s       r3   r   %SQLiteDialect_aiosqlite.is_disconnect  sR     -4
zz**
 
$A.w$QF;;r6   c                    UR                   $ r8   )r(   )r1   r   s     r3   get_driver_connection-SQLiteDialect_aiosqlite.get_driver_connection  s     %%%r6   r   )rl   r   )r   r"   rl   ztype[pool.Pool])r   zDBAPIModule.Errorr   z7Optional[Union[PoolProxiedConnection, DBAPIConnection]]rB   zOptional[DBAPICursor]rl   r   )r   r   rl   r   )rr   rs   rt   ru   driversupports_statement_cacheis_asyncsupports_server_side_cursorsr   execution_ctx_clsclassmethodr   r   r   r   rw   r   r   s   @r3   r   r     s    F#H#' 8
 

 # #<< L< &	<
 
<&)&	& &r6   r   )7__doc__
__future__r   r   collectionsr   	functoolsr   typesr   typingr   r   r	   r
   r   r   r   r   r   baser   pysqliter    r   r   connectors.asyncior   enginer   util.concurrencyr   r   r   r   engine.interfacesr   r   r   r   r    r!   
engine.urlr"   	pool.baser#   r%   ry   rj   r   r   r   r   dialectr9   r6   r3   <module>r     s   FN #               ( ,   9 ' . *<8<=>400!2f fR4%@ 4>V&7 Vr*.M *.!8 .b?'= ?
(&4 (&V "r6   