
    	h9                    P   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  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( 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/          Z0 G d( d)e          Z1 G d* d+e1          Z2 G d, d-e          Z3 G d. d/e          Z4 G d0 d1e          Z5e5Z6dS )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                  d    e Zd ZdZdZddZddZ	 dd dZd!dZd"dZ	d#dZ
d$dZdd%dZd&dZd	S )'AsyncAdapt_aiosqlite_cursor)_adapt_connection_connectiondescriptionawait__rows	arraysizerowcount	lastrowidFadapt_connectionAsyncAdapt_aiosqlite_connectionc                    || _         |j        | _        |j        | _        d| _        d| _        d | _        t                      | _        d S )Nr   )r&   r'   r)   r+   r,   r(   r   r*   )selfr.   s     q/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py__init__z$AsyncAdapt_aiosqlite_cursor.__init__   sD    !1+7&->B!&


    returnNonec                8    | j                                          d S N)r*   clearr2   s    r3   closez!AsyncAdapt_aiosqlite_cursor.close   s    
r5   N	operationr   
parameters#Optional[_DBAPISingleExecuteParams]c                   	 |                      | j                                                  }|)|                      |                    |                     n)|                      |                    ||                     |j        r[|j        | _        dx| _        | _        | j        s9t          |                      |	                                                    | _
        nd | _        |j        | _        |j        | _        | j        s)|                      |                                           d S || _        d S # t          $ r%}| j                            |           Y d }~d S d }~ww xY w)Nr1   )r)   r'   cursorexecuter(   r-   r,   server_sider   fetchallr*   r<   _cursor	Exceptionr&   _handle_exception)r2   r=   r>   rE   errors        r3   rB   z#AsyncAdapt_aiosqlite_cursor.execute   s`   	<*.++d6F6M6M6O6O*P*PG!GOOI667777GOOIzBBCCC" 	1#*#6 133' H!&t{{73C3C3E3E'F'F!G!GDJ#' !(!2 ' 0# 'GMMOO,,,,,& 	< 	< 	<"44U;;;;;;;;;	<s   D/D< 3D< <
E+E&&E+seq_of_parametersr   c                   	 |                      | j                                                  }|                      |                    ||                     d | _        |j        | _        |j        | _        |                      |                                           d S # t          $ r%}| j	        
                    |           Y d }~d S d }~ww xY wr9   )r)   r'   rA   executemanyr(   r-   r,   r<   rF   r&   rG   )r2   r=   rI   rE   rH   s        r3   rK   z'AsyncAdapt_aiosqlite_cursor.executemany   s    
	<*.++d6F6M6M6O6O*P*PGKK++I7HIIJJJ#D$.DN#,DMKK((((( 	< 	< 	<"44U;;;;;;;;;	<s   BB 
C)C		C
inputsizesc                    d S r9    )r2   rL   s     r3   setinputsizesz)AsyncAdapt_aiosqlite_cursor.setinputsizes   s    r5   Iterator[Any]c              #  `   K   | j         r$| j                                         V  | j         "d S d S r9   r*   popleftr;   s    r3   __iter__z$AsyncAdapt_aiosqlite_cursor.__iter__   sJ      j 	'*$$&&&&& j 	' 	' 	' 	' 	'r5   Optional[Any]c                F    | j         r| j                                         S d S r9   rR   r;   s    r3   fetchonez$AsyncAdapt_aiosqlite_cursor.fetchone   s%    : 	:%%'''4r5   sizeOptional[int]Sequence[Any]c           	         || j         }| j        fdt          t          |t	                                        D             S )Nc                8    g | ]}                                 S rN   )rS   ).0_rrs     r3   
<listcomp>z9AsyncAdapt_aiosqlite_cursor.fetchmany.<locals>.<listcomp>   s!    @@@

@@@r5   )r+   r*   rangeminlen)r2   rX   r_   s     @r3   	fetchmanyz%AsyncAdapt_aiosqlite_cursor.fetchmany   sH    <>DZ@@@@eCc"gg,>,>&?&?@@@@r5   c                `    t          | j                  }| j                                         |S r9   )listr*   r:   )r2   retvals     r3   rD   z$AsyncAdapt_aiosqlite_cursor.fetchall   s*    dj!!
r5   )r.   r/   r6   r7   r9   )r=   r   r>   r?   r6   r   )r=   r   rI   r   r6   r   )rL   r   r6   r7   )r6   rP   r6   rU   rX   rY   r6   rZ   r6   rZ   )__name__
__module____qualname__	__slots__rC   r4   r<   rB   rK   rO   rT   rW   rd   rD   rN   r5   r3   r%   r%   v   s        	I K) ) ) )    ;?< < < < <@< < < <   ' ' ' '   A A A A A     r5   r%   c                  J     e Zd ZdZdZd fdZdd	ZddZdddZddZ	 xZ
S )AsyncAdapt_aiosqlite_ss_cursorrE   Targr   kwr6   r7   c                H     t                      j        |i | d | _        d S r9   )superr4   rE   )r2   rr   rs   	__class__s      r3   r4   z'AsyncAdapt_aiosqlite_ss_cursor.__init__   s*    #$$$$59r5   c                ~    | j         5|                     | j                                                    d | _         d S d S r9   )rE   r)   r<   r;   s    r3   r<   z$AsyncAdapt_aiosqlite_ss_cursor.close   s=    <#KK**,,---DLLL $#r5   rU   c                l    | j         J |                     | j                                                   S r9   )rE   r)   rW   r;   s    r3   rW   z'AsyncAdapt_aiosqlite_ss_cursor.fetchone   0    |'''{{4<0022333r5   NrX   rY   rZ   c                    | j         J || j        }|                     | j                             |                    S )N)rX   )rE   r+   r)   rd   )r2   rX   s     r3   rd   z(AsyncAdapt_aiosqlite_ss_cursor.fetchmany   sA    |'''<>D{{4<11t1<<===r5   c                l    | j         J |                     | j                                                   S r9   )rE   r)   rD   r;   s    r3   rD   z'AsyncAdapt_aiosqlite_ss_cursor.fetchall   ry   r5   )rr   r   rs   r   r6   r7   rh   ri   r9   rj   rk   )rl   rm   rn   ro   rC   r4   r<   rW   rd   rD   __classcell__rv   s   @r3   rq   rq      s         IK: : : : : :       
4 4 4 4> > > > >4 4 4 4 4 4 4 4r5   rq   c                      e Zd Z ee          ZdZddZedd
            Z	e	j
        d d            Z	d!dZd"d#dZd$dZd%dZd%dZd%dZd&dZdS )'r/   )dbapir   r   
connectionr   r6   r7   c                "    || _         || _        d S r9   )r   r'   )r2   r   r   s      r3   r4   z(AsyncAdapt_aiosqlite_connection.__init__   s    
%r5   Optional[str]c                @    t          t          | j        j                  S r9   )r   strr'   isolation_levelr;   s    r3   r   z/AsyncAdapt_aiosqlite_connection.isolation_level  s    C)9:::r5   valuec                V   dd}t          || j        j        |          }t          j                                                    }| j        j                            ||f           	 |                     |           d S # t          $ r }| 
                    |           Y d }~d S d }~ww xY w)	Nr   r/   r   r   r6   r7   c                    || _         d S r9   )r   )r   r   s     r3   set_isoz@AsyncAdapt_aiosqlite_connection.isolation_level.<locals>.set_iso  s     */J&&&r5   )r   r/   r   r   r6   r7   )r   r'   _connasyncioget_event_loopcreate_future_tx
put_nowaitr)   rF   rG   )r2   r   r   functionfuturerH   s         r3   r   z/AsyncAdapt_aiosqlite_connection.isolation_level  s    	/ 	/ 	/ 	/
 7D$4$:EBB'))7799''(:;;;	*KK 	* 	* 	*""5)))))))))	*s   'A> >
B(B##B(argsrs   c                    	 |                       | j        j        |i |           d S # t          $ r }|                     |           Y d }~d S d }~ww xY wr9   )r)   r'   create_functionrF   rG   )r2   r   rs   rH   s       r3   r   z/AsyncAdapt_aiosqlite_connection.create_function  sz    	*KK8(8$E"EEFFFFF 	* 	* 	*""5)))))))))	*s   %) 
AAAFrC   boolr%   c                B    |rt          |           S t          |           S r9   )rq   r%   )r2   rC   s     r3   rA   z&AsyncAdapt_aiosqlite_connection.cursor#  s&     	51$777.t444r5   c                L    |                       | j        j        |i |          S r9   )r)   r'   rB   )r2   r   rs   s      r3   rB   z'AsyncAdapt_aiosqlite_connection.execute)  s*    {{34+3T@R@@AAAr5   c                    	 |                      | j                                                   d S # t          $ r }|                     |           Y d }~d S d }~ww xY wr9   )r)   r'   rollbackrF   rG   r2   rH   s     r3   r   z(AsyncAdapt_aiosqlite_connection.rollback,  ss    	*KK(113344444 	* 	* 	*""5)))))))))	*   ,0 
AAAc                    	 |                      | j                                                   d S # t          $ r }|                     |           Y d }~d S d }~ww xY wr9   )r)   r'   commitrF   rG   r   s     r3   r   z&AsyncAdapt_aiosqlite_connection.commit2  ss    	*KK(//1122222 	* 	* 	*""5)))))))))	*r   c                    	 |                      | j                                                   d S # t          $ r Y d S t          $ r }|                     |           Y d }~d S d }~ww xY wr9   )r)   r'   r<   
ValueErrorrF   rG   r   s     r3   r<   z%AsyncAdapt_aiosqlite_connection.close8  s    	*KK(..0011111 		 		 		 DD 	* 	* 	*""5)))))))))	*s   ,0 
A&	A&A!!A&rH   rF   r   c                    t          |t                    r1|j        d         dk    r | j        j                            d          ||)Nr   no active connection)
isinstancer   r   r   sqliteOperationalErrorr   s     r3   rG   z1AsyncAdapt_aiosqlite_connection._handle_exceptionH  sP    uj))	
1!777*#44&  Kr5   N)r   r   r   r   r6   r7   )r6   r   )r   r   r6   r7   )r   r   rs   r   r6   r7   )F)rC   r   r6   r%   )r   r   rs   r   r6   r   rh   )rH   rF   r6   r   )rl   rm   rn   staticmethodr   r)   ro   r4   propertyr   setterr   rA   rB   r   r   r<   rG   rN   r5   r3   r/   r/      s       \*%%FI& & & & ; ; ; X; * * * *** * * *5 5 5 5 5B B B B* * * ** * * ** * * * 	 	 	 	 	 	r5   r/   c                  (    e Zd ZdZ ee          ZdS )'AsyncAdaptFallback_aiosqlite_connectionrN   N)rl   rm   rn   ro   r   r   r)   rN   r5   r3   r   r   T  s"        I\.))FFFr5   r   c                  &    e Zd ZddZddZddZdS )AsyncAdapt_aiosqlite_dbapi	aiosqliter   r   c                X    || _         || _        d| _        |                                  d S )Nqmark)r   r   
paramstyle_init_dbapi_attributes)r2   r   r   s      r3   r4   z#AsyncAdapt_aiosqlite_dbapi.__init__[  s/    "!##%%%%%r5   r6   r7   c           	         dD ]&}t          | |t          | j        |                     'dD ]&}t          | |t          | j        |                     'dD ]&}t          | |t          | j        |                     'd S )N)DatabaseErrorErrorIntegrityErrorNotSupportedErrorr   ProgrammingErrorsqlite_versionsqlite_version_info)PARSE_COLNAMESPARSE_DECLTYPES)Binary)setattrgetattrr   r   )r2   names     r3   r   z1AsyncAdapt_aiosqlite_dbapi._init_dbapi_attributesa  s    	
 
	? 
	?D D$ = =>>>>9 	< 	<DD$T : :;;;; 	< 	<DD$T : :;;;;	< 	<r5   rr   r   rs   r/   c                >   |                     dd          }|                     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   r/   r   )r2   rr   rs   r   
creator_fnr   s         r3   r   z"AsyncAdapt_aiosqlite_dbapi.connectt  s     0%88VV.55
 	%#S/B//JJ//;;;J $J;~&& 		:z**  
 3:&&  r5   N)r   r   r   r   rh   )rr   r   rs   r   r6   r/   )rl   rm   rn   r4   r   r   rN   r5   r3   r   r   Z  sP        & & & &< < < <&     r5   r   c                      e Zd ZddZdS ) SQLiteExecutionContext_aiosqliter6   r    c                8    | j                             d          S )NT)rC   )_dbapi_connectionrA   r;   s    r3   create_server_side_cursorz:SQLiteExecutionContext_aiosqlite.create_server_side_cursor  s    %,,,>>>r5   N)r6   r    )rl   rm   rn   r   rN   r5   r3   r   r     s(        ? ? ? ? ? ?r5   r   c                  l     e Zd ZdZdZdZdZeZe	dd            Z
e	dd	            Zd fdZddZ xZS )SQLiteDialect_aiosqliter   Tr6   r   c                V    t          t          d          t          d                    S )Nr   sqlite3)r   
__import__)clss    r3   import_dbapiz$SQLiteDialect_aiosqlite.import_dbapi  s)    ){##Z	%:%:
 
 	
r5   urlr"   type[pool.Pool]c                \    |                      |          rt          j        S t          j        S r9   )_is_url_file_dbr   AsyncAdaptedQueuePool
StaticPool)r   r   s     r3   get_pool_classz&SQLiteDialect_aiosqlite.get_pool_class  s)    s## 	#--?"r5   eDBAPIModule.Errorr   7Optional[Union[PoolProxiedConnection, DBAPIConnection]]rA   Optional[DBAPICursor]r   c                    t          d| j                  | _        t          || j        j                  rdt	          |          v rdS t                                          |||          S )Nr!   r   T)r   r   r   r   r   ru   is_disconnect)r2   r   r   rA   rv   s       r3   r   z%SQLiteDialect_aiosqlite.is_disconnect  sf     -44
tz*
 
 	$A..4ww$$Q
F;;;r5   r   r   c                    |j         S r9   )r'   )r2   r   s     r3   get_driver_connectionz-SQLiteDialect_aiosqlite.get_driver_connection  s     %%r5   )r6   r   )r   r"   r6   r   )r   r   r   r   rA   r   r6   r   )r   r   r6   r   )rl   rm   rn   driversupports_statement_cacheis_asyncsupports_server_side_cursorsr   execution_ctx_clsclassmethodr   r   r   r   r|   r}   s   @r3   r   r     s        F#H#' 8
 
 
 [

 # # # [#< < < < < <& & & & & & & &r5   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%   rq   r/   r   r   r   r   dialectrN   r5   r3   <module>r      s  F FN # " " " " "                                                                                ( ( ( ( ( ( , , , , , ,             9 9 9 9 9 9 ' ' ' ' ' ' . . . . . . * * * * * * 
3<<<<<<888888<<<<<<======>>>>>>444444000000000000!!!!!!222222c c c c c c c cL4 4 4 4 4%@ 4 4 4>V V V V V&7 V V Vr* * * * *.M * * *. . . . .!8 . . .b? ? ? ? ?'= ? ? ?
(& (& (& (& (&4 (& (& (&V "r5   