L iZ9$dZddlmZddlZddlmZddlmZddlm Z ddl m Z ddl m Z dd l m Z dd l mZdd l mZdd l mZdd l mZddl mZddl mZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!er` 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)PoolProxiedConnectionceZdZdZdZddZddZddZ d ddZ ddZ dd Z dd Z dd Z ddd Z dd Zy)AsyncAdapt_aiosqlite_cursor)_adapt_connection _connection descriptionawait__rows arraysizerowcount lastrowidFc||_|j|_|j|_d|_d|_d|_t |_y)Nr)r&r'r)r+r,r(rr*)selfadapt_connections j/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/dialects/sqlite/aiosqlite.py__init__z$AsyncAdapt_aiosqlite_cursor.__init__sD!1+77&--  >B!& c KywNr0s r2_async_soft_closez-AsyncAdapt_aiosqlite_cursor._async_soft_closes sc8|jjyr6)r*clearr8s r2closez!AsyncAdapt_aiosqlite_cursor.closes r4Nc |j|jj}|!|j|j|n!|j|j|||jrY|j|_dx|_|_|jsWt|j|j|_ n)d|_|j |_|j |_|js |j|jy||_ y#t$r%}|jj|Yd}~yd}~wwxYw)Nr/)r)r'cursorexecuter(r-r, server_siderfetchallr*r<_cursor Exceptionr&_handle_exception)r0 operation parametersrBerrors r2r?z#AsyncAdapt_aiosqlite_cursor.executes   <*.++d6F6F6M6M6O*PG! GOOI67 GOOIzBC""#*#6#6 133''!&t{{73C3C3E'F!GDJ#' !(!2!2 ' 0 0 ## GMMO,&  <  " " 4 4U ; ; executemanyr(r-r,r<rCr&rD)r0rEseq_of_parametersrBrGs r2rIz'AsyncAdapt_aiosqlite_cursor.executemanys  <*.++d6F6F6M6M6O*PG KK++I7HI J#D $..DN#,,DM KK  ( <  " " 4 4U ; ; >Ccyr6r7)r0 inputsizess r2 setinputsizesz)AsyncAdapt_aiosqlite_cursor.setinputsizess r4c#xK|jr*|jj|jr)yywr6r*popleftr8s r2__iter__z$AsyncAdapt_aiosqlite_cursor.__iter__s)jj**$$& &jjs5::cP|jr|jjSyr6rOr8s r2fetchonez$AsyncAdapt_aiosqlite_cursor.fetchones ::::%%' 'r4c| |j}|j}tt|t |Dcgc]}|j c}Scc}wr6)r+r*rangeminlenrP)r0sizerr_s r2 fetchmanyz%AsyncAdapt_aiosqlite_cursor.fetchmanysC <>>D ZZ&+Cc"g,>&?@ @@@sAcdt|j}|jj|Sr6)listr*r;)r0retvals r2rAz$AsyncAdapt_aiosqlite_cursor.fetchalls%djj!  r4)r1AsyncAdapt_aiosqlite_connectionreturnNoner6)rErrFz#Optional[_DBAPISingleExecuteParams]rar)rErrJrrar)rLrrarb)raz Iterator[Any]raz Optional[Any]rXz Optional[int]ra Sequence[Any]rare)__name__ __module__ __qualname__ __slots__r@r3r9r<r?rIrMrQrSr[rAr7r4r2r%r%vs IK) ;?<<8< <@ < <4 < < ' Ar4r%cJeZdZdZdZdfd Zd dZd dZd d dZd dZ xZ S)AsyncAdapt_aiosqlite_ss_cursorrBTc2t||i|d|_yr6)superr3rB)r0argkw __class__s r2r3z'AsyncAdapt_aiosqlite_ss_cursor.__init__s #$$59 r4c~|j1|j|jjd|_yyr6)rBr)r<r8s r2r<z$AsyncAdapt_aiosqlite_ss_cursor.closes1 << # KK **, -DL $r4cp|jJ|j|jjSr6)rBr)rSr8s r2rSz'AsyncAdapt_aiosqlite_ss_cursor.fetchone.||'''{{4<<00233r4c|jJ| |j}|j|jj|S)N)rX)rBr+r)r[)r0rXs r2r[z(AsyncAdapt_aiosqlite_ss_cursor.fetchmanysA||''' <>>D{{4<<11t1<==r4cp|jJ|j|jjSr6)rBr)rAr8s r2rAz'AsyncAdapt_aiosqlite_ss_cursor.fetchallrtr4)rorrprrarbr`rcr6rdrf) rgrhrirjr@r3r<rSr[rA __classcell__rqs@r2rlrls(IK: 4> 4r4rlceZdZeeZdZd dZeddZ e jddZ ddZ dddZ ddZ ddZdd Zdd Zdd Zy )r_)dbapic ||_||_yr6)rzr')r0rz connections r2r3z(AsyncAdapt_aiosqlite_connection.__init__s %r4cJtt|jjSr6)rstrr'isolation_levelr8s r2rz/AsyncAdapt_aiosqlite_connection.isolation_levelsC))99::r4c^ dd}t||jj|}tjj }|jj j||f |j|y#t$r}|j|Yd}~yd}~wwxYw)Nc||_yr6)r)r|values r2set_isoz@AsyncAdapt_aiosqlite_connection.isolation_level..set_isos */J &r4)r|r_r Optional[str]rarb) rr'_connasyncioget_event_loop create_future_tx put_nowaitr)rCrD)r0rrfunctionfuturerGs r2rz/AsyncAdapt_aiosqlite_connection.isolation_level s /7 /@M /  / 7D$4$4$:$:EB'')779 ''(:; * KK  *  " "5 ) ) *s6B B,B''B,c |j|jj|i|y#t$r}|j |Yd}~yd}~wwxYwr6)r)r'create_functionrCrD)r0argsrprGs r2rz/AsyncAdapt_aiosqlite_connection.create_function sM * KK8((88$E"E F *  " "5 ) ) *s+. AA  Ac2|r t|St|Sr6)rlr%)r0r@s r2r>z&AsyncAdapt_aiosqlite_connection.cursor&s 1$7 7.t4 4r4cX|j|jj|i|Sr6)r)r'r?)r0rrps r2r?z'AsyncAdapt_aiosqlite_connection.execute,s*{{34++33T@R@AAr4c |j|jjy#t$r}|j |Yd}~yd}~wwxYwr6)r)r'rollbackrCrDr0rGs r2rz(AsyncAdapt_aiosqlite_connection.rollback/sC * KK((113 4 *  " "5 ) ) *), AA  Ac |j|jjy#t$r}|j |Yd}~yd}~wwxYwr6)r)r'commitrCrDrs r2rz&AsyncAdapt_aiosqlite_connection.commit5sC * KK((//1 2 *  " "5 ) ) *rc |j|jjy#t$rYyt$r}|j |Yd}~yd}~wwxYwr6)r)r'r< ValueErrorrCrDrs r2r<z%AsyncAdapt_aiosqlite_connection.close;sP * KK((..0 1   *  " "5 ) ) *s), AAAAct|tr8|jddk(r&|jjj d||)Nrno active connection) isinstancerrrzsqliteOperationalErrorrs r2rDz1AsyncAdapt_aiosqlite_connection._handle_exceptionKsG uj ) 1 !77**##44& Kr4N)rzrr|rrarb)rar)rrrarb)rrrprrarb)F)r@boolrar%)rrrprrarr`)rGrCrar )rgrhri staticmethodrr)rjr3propertyrsetterrr>r?rrr<rDr7r4r2r_r_sh * %FI&;;**** 5 B* * * r4r_c eZdZdZeeZy)'AsyncAdaptFallback_aiosqlite_connectionr7N)rgrhrirjrrr)r7r4r2rrWsI . )Fr4rc$eZdZddZddZddZy)AsyncAdapt_aiosqlite_dbapicN||_||_d|_|jy)Nqmark) aiosqliter paramstyle_init_dbapi_attributes)r0rrs r2r3z#AsyncAdapt_aiosqlite_dbapi.__init__^s#" ! ##%r4c dD]#}t||t|j|%dD]#}t||t|j|%dD]#}t||t|j|%y)N) DatabaseErrorErrorIntegrityErrorNotSupportedErrorrProgrammingErrorsqlite_versionsqlite_version_info)PARSE_COLNAMESPARSE_DECLTYPES)Binary)setattrgetattrrr)r0names r2rz1AsyncAdapt_aiosqlite_dbapi._init_dbapi_attributesds|  ?D D$ = > ?: r8s r2create_server_side_cursorz:SQLiteExecutionContext_aiosqlite.create_server_side_cursors%%,,,>>r4N)rar )rgrhrirr7r4r2rrs?r4rcxeZdZdZdZdZdZeZe ddZ e ddZ d fd Z d dZ xZS) SQLiteDialect_aiosqliterTc>ttdtdS)Nrsqlite3)r __import__)clss r2 import_dbapiz$SQLiteDialect_aiosqlite.import_dbapis) { #Z %:  r4cd|j|rtjStjSr6)_is_url_file_dbrAsyncAdaptedQueuePool StaticPool)rurls r2get_pool_classz&SQLiteDialect_aiosqlite.get_pool_classs&   s #-- -?? "r4ctd|j|_t||jjrdt |vryt ||||S)Nr!rT)rrzrrr~rn is_disconnect)r0er|r>rqs r2rz%SQLiteDialect_aiosqlite.is_disconnectsQ -4  tzz** $A.w$Q F;;r4c|jSr6)r')r0r|s r2get_driver_connectionz-SQLiteDialect_aiosqlite.get_driver_connections%%%r4)rar)rr"raztype[pool.Pool])rzDBAPIModule.Errorr|z7Optional[Union[PoolProxiedConnection, DBAPIConnection]]r>zOptional[DBAPICursor]rar)r|rrar)rgrhridriversupports_statement_cacheis_asyncsupports_server_side_cursorsrexecution_ctx_cls classmethodrrrrrwrxs@r2rrs F#H#' 8  ## <  <L <& <  <&)& &r4r)7__doc__ __future__rr collectionsr functoolsrtypesrtypingrrr r r r r rrbaserpysqliterrrconnectors.asynciorenginerutil.concurrencyrrrrengine.interfacesrrrrr r! engine.urlr" pool.baser#r%rlr_rrrrdialectr7r4r2rsFN# (,9'.*<8<=>400!2ffR4%@4>V&7Vr*.M* .!8.b?'=? (&4(&V "r4