L iddZddlmZddlmZddlZddlZddlZddl Z ddl mZddl m Z ddl m Zdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddl m Z ddl m!Z!ddl m"Z"ddl#m$Z$ddl%m&Z&ddl%m'Z'ddl(m)Z)dd l*m+Z+dd!l*m,Z,dd"l*m-Z-Gd#d$eZ.Gd%d&e)j^Z0Gd'd(eZ1Gd)d*e)jdZ3Gd+d,eZ4Gd-d.eZ5Gd/d0e)jlZ7Gd1d2e)jpZ9Gd3d4e)jtZ;Gd5d6eZ<Gd7d8eZ=Gd9d:e)j|Z?Gd;de)jZCGd?d@ejZEGdAdBejZGGdCdDe)jjZIGdEdFe)jjZKGdGdHe)jjZMGdIdJejZOGdKdLe)jZQGdMdNeQe)jZSGdOdPeZTGdQdReZUGdSdTe)jZWGdUdVe jZYGdWdXe jZ[GdYdZeZ\Gd[d\eZ]Gd]d^eZ^Gd_d`Z_Gdadbe_Z`Gdcdde$e&ZaGdedfeaZbGdgdhZcGdidjeZdedZey)ka .. dialect:: postgresql+asyncpg :name: asyncpg :dbapi: asyncpg :connectstring: postgresql+asyncpg://user:password@host:port/dbname[?key=value&key=value...] :url: https://magicstack.github.io/asyncpg/ The asyncpg dialect is SQLAlchemy's first Python asyncio dialect. Using a special asyncio mediation layer, the asyncpg dialect is usable as the backend for the :ref:`SQLAlchemy asyncio ` 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( "postgresql+asyncpg://user:pass@hostname/dbname" ) .. versionadded:: 1.4 .. note:: By default asyncpg does not decode the ``json`` and ``jsonb`` types and returns them as strings. SQLAlchemy sets default type decoder for ``json`` and ``jsonb`` types using the python builtin ``json.loads`` function. The json implementation used can be changed by setting the attribute ``json_deserializer`` when creating the engine with :func:`create_engine` or :func:`create_async_engine`. .. _asyncpg_multihost: Multihost Connections -------------------------- The asyncpg dialect features support for multiple fallback hosts in the same way as that of the psycopg2 and psycopg dialects. The syntax is the same, using ``host=:`` combinations as additional query string arguments; however, there is no default port, so all hosts must have a complete port number present, otherwise an exception is raised:: engine = create_async_engine( "postgresql+asyncpg://user:password@/dbname?host=HostA:5432&host=HostB:5432&host=HostC:5432" ) For complete background on this syntax, see :ref:`psycopg2_multi_host`. .. versionadded:: 2.0.18 .. seealso:: :ref:`psycopg2_multi_host` .. _asyncpg_prepared_statement_cache: Prepared Statement Cache -------------------------- The asyncpg SQLAlchemy dialect makes use of ``asyncpg.connection.prepare()`` for all statements. The prepared statement objects are cached after construction which appears to grant a 10% or more performance improvement for statement invocation. The cache is on a per-DBAPI connection basis, which means that the primary storage for prepared statements is within DBAPI connections pooled within the connection pool. The size of this cache defaults to 100 statements per DBAPI connection and may be adjusted using the ``prepared_statement_cache_size`` DBAPI argument (note that while this argument is implemented by SQLAlchemy, it is part of the DBAPI emulation portion of the asyncpg dialect, therefore is handled as a DBAPI argument, not a dialect argument):: engine = create_async_engine( "postgresql+asyncpg://user:pass@hostname/dbname?prepared_statement_cache_size=500" ) To disable the prepared statement cache, use a value of zero:: engine = create_async_engine( "postgresql+asyncpg://user:pass@hostname/dbname?prepared_statement_cache_size=0" ) .. versionadded:: 1.4.0b2 Added ``prepared_statement_cache_size`` for asyncpg. .. warning:: The ``asyncpg`` database driver necessarily uses caches for PostgreSQL type OIDs, which become stale when custom PostgreSQL datatypes such as ``ENUM`` objects are changed via DDL operations. Additionally, prepared statements themselves which are optionally cached by SQLAlchemy's driver as described above may also become "stale" when DDL has been emitted to the PostgreSQL database which modifies the tables or other objects involved in a particular prepared statement. The SQLAlchemy asyncpg dialect will invalidate these caches within its local process when statements that represent DDL are emitted on a local connection, but this is only controllable within a single Python process / database engine. If DDL changes are made from other database engines and/or processes, a running application may encounter asyncpg exceptions ``InvalidCachedStatementError`` and/or ``InternalServerError("cache lookup failed for type ")`` if it refers to pooled database connections which operated upon the previous structures. The SQLAlchemy asyncpg dialect will recover from these error cases when the driver raises these exceptions by clearing its internal caches as well as those of the asyncpg driver in response to them, but cannot prevent them from being raised in the first place if the cached prepared statement or asyncpg type caches have gone stale, nor can it retry the statement as the PostgreSQL transaction is invalidated when these errors occur. .. _asyncpg_prepared_statement_name: Prepared Statement Name with PGBouncer -------------------------------------- By default, asyncpg enumerates prepared statements in numeric order, which can lead to errors if a name has already been taken for another prepared statement. This issue can arise if your application uses database proxies such as PgBouncer to handle connections. One possible workaround is to use dynamic prepared statement names, which asyncpg now supports through an optional ``name`` value for the statement name. This allows you to generate your own unique names that won't conflict with existing ones. To achieve this, you can provide a function that will be called every time a prepared statement is prepared:: from uuid import uuid4 engine = create_async_engine( "postgresql+asyncpg://user:pass@somepgbouncer/dbname", poolclass=NullPool, connect_args={ "prepared_statement_name_func": lambda: f"__asyncpg_{uuid4()}__", }, ) .. seealso:: https://github.com/MagicStack/asyncpg/issues/837 https://github.com/sqlalchemy/sqlalchemy/issues/6467 .. warning:: When using PGBouncer, to prevent a buildup of useless prepared statements in your application, it's important to use the :class:`.NullPool` pool class, and to configure PgBouncer to use `DISCARD `_ when returning connections. The DISCARD command is used to release resources held by the db connection, including prepared statements. Without proper setup, prepared statements can accumulate quickly and cause performance issues. Disabling the PostgreSQL JIT to improve ENUM datatype handling --------------------------------------------------------------- Asyncpg has an `issue `_ when using PostgreSQL ENUM datatypes, where upon the creation of new database connections, an expensive query may be emitted in order to retrieve metadata regarding custom types which has been shown to negatively affect performance. To mitigate this issue, the PostgreSQL "jit" setting may be disabled from the client using this setting passed to :func:`_asyncio.create_async_engine`:: engine = create_async_engine( "postgresql+asyncpg://user:password@localhost/tmp", connect_args={"server_settings": {"jit": "off"}}, ) .. seealso:: https://github.com/MagicStack/asyncpg/issues/727 ) annotations)dequeN)json)ranges)ARRAY)_DECIMAL_TYPES) _FLOAT_TYPES) _INT_TYPES)ENUM)INTERVAL)OID) PGCompiler) PGDialect)PGExecutionContext)PGIdentifierPreparer)REGCLASS) REGCONFIG)BIT)BYTEA)CITEXT)exc)pool)util)AsyncAdapt_terminate)AdaptedConnection) processors)sqltypes)asyncio)await_fallback) await_onlyceZdZdZy) AsyncpgARRAYTN__name__ __module__ __qualname__render_bind_castl/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/asyncpg.pyr$r$r+r$ceZdZdZy) AsyncpgStringTNr%r*r+r,r/r/r-r+r/ceZdZdZy)AsyncpgREGCONFIGTNr%r*r+r,r1r1r-r+r1ceZdZdZy) AsyncpgTimeTNr%r*r+r,r3r3r-r+r3ceZdZdZy) AsyncpgBitTNr%r*r+r,r5r5r-r+r5ceZdZdZy) AsyncpgByteATNr%r*r+r,r7r7r-r+r7ceZdZdZy) AsyncpgDateTNr%r*r+r,r9r9r-r+r9ceZdZdZy)AsyncpgDateTimeTNr%r*r+r,r;r;r-r+r;ceZdZdZy)AsyncpgBooleanTNr%r*r+r,r=r=r-r+r=c eZdZdZedZy)AsyncPgIntervalTc .t|jS)N) precision)r?second_precision)clsintervalkws r,adapt_emulated_to_nativez(AsyncPgInterval.adapt_emulated_to_natives)B)BCCr+N)r&r'r(r) classmethodrFr*r+r,r?r?sDDr+r?ceZdZdZy) AsyncPgEnumTNr%r*r+r,rIrIr-r+rIceZdZdZy)AsyncpgIntegerTNr%r*r+r,rKrK r-r+rKceZdZdZy)AsyncpgSmallIntegerTNr%r*r+r,rMrM r-r+rMceZdZdZy)AsyncpgBigIntegerTNr%r*r+r,rOrOr-r+rOceZdZdZy) AsyncpgJSONcyNr*selfdialectcoltypes r,result_processorzAsyncpgJSON.result_processorr+Nr&r'r(rXr*r+r,rQrQr+rQceZdZdZy) AsyncpgJSONBcyrSr*rTs r,rXzAsyncpgJSONB.result_processorrYr+NrZr*r+r,r]r]r[r+r]c eZdZy)AsyncpgJSONIndexTypeNr&r'r(r*r+r,r`r`r+r`ceZdZdZdZy)AsyncpgJSONIntIndexTypejson_int_indexTNr&r'r(__visit_name__r)r*r+r,rdrd# %Nr+rdceZdZdZdZy)AsyncpgJSONStrIndexTypejson_str_indexTNrfr*r+r,rjrj)rhr+rjceZdZdZy)AsyncpgJSONPathTypec d}|S)Nclt|tr|S|r|Dcgc] }t|}}|SgScc}wrS isinstancestr)valueelemtokenss r,processz3AsyncpgJSONPathType.bind_processor..process1s<%% 056#d)66  7s1r*)rUrVrvs r,bind_processorz"AsyncpgJSONPathType.bind_processor0s r+N)r&r'r(rwr*r+r,rmrm/s r+rmceZdZdZdZdZy)AsyncpgNumericTcyrSr*)rUrVs r,rwzAsyncpgNumeric.bind_processorBrYr+cZ|jr_|tvr.tjtj |j S|tvs|tvrytjd|z|tvry|tvs|tvrtjStjd|z)NzUnknown PG numeric type: %d) asdecimalr rto_decimal_processor_factorydecimalDecimal_effective_decimal_return_scaler r rInvalidRequestErrorto_floatrTs r,rXzAsyncpgNumeric.result_processorEs >>,&!>>OOT%I%IN*g.C--1G;,&N*g.C!***--1G;r+N)r&r'r(r)rwrXr*r+r,ryry?sr+ryceZdZdZdZy) AsyncpgFloatfloatTNrfr*r+r,rr^s Nr+rceZdZdZy)AsyncpgREGCLASSTNr%r*r+r,rrcr-r+rceZdZdZy) AsyncpgOIDTNr%r*r+r,rrgr-r+rceZdZdZy) AsyncpgCHARTNr%r*r+r,rrkr-r+rceZdZdZdZy) _AsyncpgRangecR|jjjfd}|S)Nct|tjrK|j|j|j ddk(|j ddk(|j }|SNr[r]) lower_inc upper_incemptyrqrRangelowerupperboundsrrs asyncpg_Ranges r,to_rangez._AsyncpgRange.bind_processor..to_rangessW%.%KKKK#ll1o4#ll1o4++ Lr+)dbapiasyncpgr)rUrVrrs @r,rwz_AsyncpgRange.bind_processorps$ --33  r+c d}|S)Nc|]|j}tj|j|j|s |j rdnd|s|j rdnd|}|SNr(r))rrisemptyrrrrrr)rsrs r,rz0_AsyncpgRange.result_processor..to_ranges]   KKKK%*eooc3G"'EOOsEG Lr+r*)rUrVrWrs r,rXz_AsyncpgRange.result_processors r+Nr&r'r(rwrXr*r+r,rros  r+rceZdZdZdZy)_AsyncpgMultiRangecl|jjjtdfd}|S)Nclt|tfr|Sfd}|Dcgc] }|| c}Scc}w)Nct|tjrK|j|j|j ddk(|j ddk(|j }|Srrrs r,rzE_AsyncpgMultiRange.bind_processor..to_range..to_rangesWeV\\2)  "',,q/S"8"',,q/S"8#kk E r+rp)rsrelementNoneTypers r,rz3_AsyncpgMultiRange.bind_processor..to_ranges6%#x1  6;;'HW%; ;;s1)rrrtype)rUrVrrrs @@r,rwz!_AsyncpgMultiRange.bind_processors- --33 : <"r+c d}|S)NcNd|tjfd|D}|S)Nc|]|j}tj|j|j|s |j rdnd|s|j rdnd|}|Srr)rvaluers r,rzM_AsyncpgMultiRange.result_processor..to_range_array..to_rangesa%"NNE#\\  ).&2B2B#!L&+0@0@3cJ L# F r+c3.K|] }|ywrSr*).0rtrs r, zN_AsyncpgMultiRange.result_processor..to_range_array..s)KT(4.)Ks)r MultiRange)rsrs @r,to_range_arrayz;_AsyncpgMultiRange.result_processor..to_range_arrays+  )))KU)KKLr+r*)rUrVrWrs r,rXz#_AsyncpgMultiRange.result_processors $r+Nrr*r+r,rrs 0r+rceZdZdZdZdZy)PGExecutionContext_asyncpgct||jjj|jjjfr|jj yyrS)rqrVrInvalidCachedStatementErrorInternalServerError_invalidate_schema_cache)rUes r,handle_dbapi_exceptionz1PGExecutionContext_asyncpg.handle_dbapi_exceptionsO   "">> ""66   LL 1 1 3 r+c|jr|jj|jj|j_|j syyrS)isddlrVr_invalidate_schema_cache_asofcursorcompiledrUs r,pre_execz#PGExecutionContext_asyncpg.pre_execsE :: LL 1 1 3 LL 6 6 1}} r+c:|jjdS)NT) server_side)_dbapi_connectionrrs r,create_server_side_cursorz4PGExecutionContext_asyncpg.create_server_side_cursors%%,,,>>r+N)r&r'r(rrrr*r+r,rrs4 ?r+rc eZdZy)PGCompiler_asyncpgNrar*r+r,rrrbr+rc eZdZy)PGIdentifierPreparer_asyncpgNrar*r+r,rrrbr+rcxeZdZUdZdZdZded<dZddZdZ dZ d Z d Z dd Z d ZdZdZdZddZdZy )AsyncAdapt_asyncpg_cursor)_adapt_connection _connection_rows description arraysizerowcount_cursorrFbool_awaitable_cursor_closec||_|j|_t|_d|_d|_d|_d|_d|_y)Nrr) rrrrrrrrr)rUadapt_connections r,__init__z"AsyncAdapt_asyncpg_cursor.__init__sF!1+77W   -.*r+c KywrSr*rs r,_async_soft_closez+AsyncAdapt_asyncpg_cursor._async_soft_closes sc8|jjyrS)rclearrs r,closezAsyncAdapt_asyncpg_cursor.closes r+c:|jj|yrS)r_handle_exceptionrUerrors r,rz+AsyncAdapt_asyncpg_cursor._handle_exceptions 007r+c K|j}|j4d{|js|jd{|d} |j ||j d{\}}|r;|Dcgc])}|j |jjdddddf+c}|_ nd|_ |jr$|j|d{|_ d|_ nxt|j|d{|_|j#}t%j&d|xsd}|r t)|j+d|_ nd|_ dddd{y7R717 cc}w77#t,$r} |j/| Yd} ~ Bd} ~ wwxYw7>#1d{7swYyxYww)Nr*rz)(?:SELECT|UPDATE|DELETE|INSERT \d+) (\d+)r)r_execute_mutex_started_start_transaction_preparernameroidrrrrrrfetchr get_statusmsgrematchintgroup Exceptionr) rU operation parametersr prepared_stmt attributesattrstatusregrs r,_prepare_and_executez.AsyncAdapt_asyncpg_cursor._prepare_and_executes11#22- .- .#,,&99;;;! & .2B2K2KtAA3-) z%/ (!!II IIMM      (D$(,D$##)=)=)=z)J#JDL$&DM!&-@]-@-@*-M'M!NDJ*88:F((D "C(+CIIaL(9 (* U- .- .- .; - ( $K(N .&&u-- .Y- .- .- .- .sGE1G F,E4F, F,E7- F:.E:(.FE?(F?F A F G+F*,G4F,7F:FF F' F"F,"F''F,*G,F>2F5 3F>:GcK|j}d|_|j4d{|j|jd{|j s|j d{ |jj||d{cdddd{S77`7>77 #t$r}|j|Yd}~nd}~wwxYwdddd{7y#1d{7swYyxYwwrS) rrr_check_type_cache_invalidationrrrr executemanyrr)rUrseq_of_parametersrrs r, _executemanyz&AsyncAdapt_asyncpg_cursor._executemany5s11#22 . ."AA22  $,,&99;;; .!--990 . . .  < . .&&u-- . . . . . .s$DB(DC+ B* #C+-B,.C+3B2B.B2 D"B0#D*C+,C+.B20D2 C;C C+CC+ D$C'%D+C=1C4 2C=9DNcZ|jj|j||yrS)rawait_r)rUrrs r,executez!AsyncAdapt_asyncpg_cursor.executeHs& %%  % %i < r+cX|jj|j||SrS)rrrrUrrs r,rz%AsyncAdapt_asyncpg_cursor.executemanyMs,%%,,   i): ;  r+ctrSNotImplementedError)rU inputsizess r, setinputsizesz'AsyncAdapt_asyncpg_cursor.setinputsizesRs !##r+c#xK|jr*|jj|jr)yywrSrpopleftrs r,__iter__z"AsyncAdapt_asyncpg_cursor.__iter__Us)jj**$$& &jjs5::cP|jr|jjSyrSrrs r,fetchonez"AsyncAdapt_asyncpg_cursor.fetchoneYs ::::%%' 'r+c| |j}|j}tt|t |Dcgc]}|j c}Scc}wrS)rrrangeminlenr)rUsizerr_s r, fetchmanyz#AsyncAdapt_asyncpg_cursor.fetchmany_sC <>>D ZZ&+Cc"g,>&?@ @@@sAcdt|j}|jj|SrS)listrr)rUretvals r,fetchallz"AsyncAdapt_asyncpg_cursor.fetchallfs%djj!  r+returnNonerS)r&r'r( __slots__rr__annotations__rrrrrrrrr rrrrr*r+r,rrs^ IK$)T)/80.d.&  $' Ar+rc^eZdZdZdZfdZdZdZdZdZ dZ d d Z d Z d Z d ZxZS)AsyncAdapt_asyncpg_ss_cursorT) _rowbuffercBt||t|_yrS)superrrr')rUr __class__s r,rz%AsyncAdapt_asyncpg_ss_cursor.__init__ps )*'r+cFd|_|jjyrS)rr'rrs r,rz"AsyncAdapt_asyncpg_ss_cursor.closets  r+c|jJ|jj|jjd}|jj |y)N2)rrrrr'extend)rUnew_rowss r, _buffer_rowsz)AsyncAdapt_asyncpg_ss_cursor._buffer_rowsxsI||'''))001C1CB1GH x(r+c|SrSr*rs r, __aiter__z&AsyncAdapt_asyncpg_ss_cursor.__aiter__}s r+cK |jr*|jj|jr*|j|jsyTwrS)r'rr0rs r, __anext__z&AsyncAdapt_asyncpg_ss_cursor.__anext__sI//oo--////    ?? s 7AAc|js|j|jsy|jjSrS)r'r0rrs r,rz%AsyncAdapt_asyncpg_ss_cursor.fetchones2    ??&&((r+c||jS|js|j|jJ|j}t |}||kDrF|j |j j|jj||z tt|t |Dcgc]}|jc}Scc}wrS) rr'r0rrr.rrrrrr)rUrrblbrs r,rz&AsyncAdapt_asyncpg_ss_cursor.fetchmanys <==? "    ||''' __ W "9 II&&--dll.@.@.KL ',Cc"g,>&?@ @@@s?Cct|j}|j|jj |j |jj |SrS)rr'r.rr_allr)rUrets r,rz%AsyncAdapt_asyncpg_ss_cursor.fetchallsH4??# 4))00=>  r+cKg} |jjdd{}|r|j|8 |S7w)Ni)rrr.)rUrowsbatchs r,r:z!AsyncAdapt_asyncpg_ss_cursor._allsF,,,,T22E E" 3s"AAActd)Nz2server side cursor doesn't support executemany yetr rs r,rz(AsyncAdapt_asyncpg_ss_cursor.executemanys! @  r+rS)r&r'r(rr#rrr0r2r4rrrr:r __classcell__r*s@r,r&r&ls@KI" ) )A"  r+r&ceZdZdZeeZ ddZdZdZ dZ e dZ e jdZ dZd Zd Zd Zdd Zd ZdZdZdZdZfdZddZddZedZxZS)AsyncAdapt_asyncpg_connection) risolation_level_isolation_settingreadonly deferrable _transactionr_prepared_statement_cache_prepared_statement_name_funcrrcV||_||_dx|_|_d|_d|_d|_d|_tj|_ tj|_ |rtj||_nd|_|r||_y|j"|_yNF)rrrDrErFrGrHrtimerr LockrrLRUCacherIrJ_default_name_func)rUr connectionprepared_statement_cache_sizeprepared_statement_name_funcs r,rz&AsyncAdapt_asyncpg_connection.__init__s %9==t6   -1YY[*%lln (-1]]-.D *.2D * '1MD .151H1HD .r+cK||jkDr*|jjd{||_yy7 wrS)rrreload_schema_state)rUinvalidate_timestamps r,rz>@7  #113 ):tyy{Cij((9 H$ s5C.C(AC.C*AC.5C,63C.*C.,C.c`|jjrd|_d|_t |t j sk|jj}t|jD];}||vs||t|d|}t|ddx|_ |_ ||||)NFz: sqlstate)r is_closedrHrrqAsyncAdapt_asyncpg_dbapiErrorr_asyncpg_error_translater__mro__getattrpgcoder])rUrexception_mappingsuper_translated_errors r,rz/AsyncAdapt_asyncpg_connection._handle_exception s    % % ' $D !DM%!9!?!?@ $ C C u+-- ..'@'8'@$(K7($ z48$+.>.G+5  Kr+c |jdk(SN autocommit)rDrs r,rjz(AsyncAdapt_asyncpg_connection.autocommit#s##|33r+c:|rd|_y|j|_yri)rDrErUrss r,rjz(AsyncAdapt_asyncpg_connection.autocommit's #/D #'#:#:D r+c |j|j}y#t$r}|j|Yd}~yd}~wwxYwrS)r _async_pingrr)rUrrs r,pingz"AsyncAdapt_asyncpg_connection.ping.s? * D,,./A *  " "5 ) ) *s" AAAcK|j~|jdk7ro|jj}|j d{ |jj dd{|j d{y|jj dd{y7e7C7-#|j d{7wxYw7)w)Nrj;)rHrDr transactionstartfetchrowrollback)rUtrs r,rnz)AsyncAdapt_asyncpg_connection._async_ping4s    $)=)=)M!!--/B((*   $&&//444kkm##""++C0 0 0 4#bkkm## 0sfA C B1 CB7/B30B74CB5#C+C,C3B75C7C C CCcX|jr|j|x|_|_yrS)rrurDrE)rUlevels r,set_isolation_levelz1AsyncAdapt_asyncpg_connection.set_isolation_levelAs" == MMO9>>t6r+cTK|jdk(ry |jj|j|j|j|_|j j d{d|_y7 #t$r}|j|Yd}~yd}~wwxYww)Nrj) isolationrFrGT) rDrrrrFrGrHrsrrrrs r,rz0AsyncAdapt_asyncpg_connection._start_transactionFs   < /  ! $ 0 0 < <..??!=!D  ##))+ + +!DM , *  " "5 ) ) *sAB(AB2A?3B7B(?B B% B B( B%%B(c2|r t|St|SrS)r&r)rUrs r,rz$AsyncAdapt_asyncpg_connection.cursorVs /5 5,T2 2r+cK |jjd{d|_d|_y7#d|_d|_wxYwwrL)rHrurrs r,_rollback_and_discardz3AsyncAdapt_asyncpg_connection._rollback_and_discard\sK "##,,. . .!%D !DM /!%D !DM%A 757A 7AA cK |jjd{d|_d|_y7#d|_d|_wxYwwrL)rHcommitrrs r,_commit_and_discardz1AsyncAdapt_asyncpg_connection._commit_and_discardesK "##**, , ,!%D !DM -!%D !DMrc|jr/ |j|jd|_d|_yy#t$r}|j |Yd}~yd}~wwxYwrL)rrr~rHrrrs r,ruz&AsyncAdapt_asyncpg_connection.rollbackns\ == . D6689$(! %   .&&u-- .-= A!AA!c|jr/ |j|jd|_d|_yy#t$r}|j |Yd}~yd}~wwxYwrL)rrrrHrrrs r,rz$AsyncAdapt_asyncpg_connection.commitys\ == . D4467$(! %   .&&u-- .rcv|j|j|jjyrS)rurrrrs r,rz#AsyncAdapt_asyncpg_connection.closes&  D$$**,-r+cdt||jjjfzSrS)r)_terminate_handled_exceptionsrr PostgresError)rUr*s r,rz;AsyncAdapt_asyncpg_connection._terminate_handled_exceptionss0w46 JJ   , ,:   r+cfK|jjdd{d|_y7 w)N)timeoutF)rrrrs r,_terminate_graceful_closez7AsyncAdapt_asyncpg_connection._terminate_graceful_closes/$$Q$///  0s 1/ 1cF|jjd|_yrL)r terminaterrs r,_terminate_force_closez4AsyncAdapt_asyncpg_connection._terminate_force_closes ""$ r+cyrSr*r*r+r,rPz0AsyncAdapt_asyncpg_connection._default_name_funcsr+)dN)Fr )r&r'r(r# staticmethodr"rrrrrpropertyrjsetterrornryrrr~rrurrrrrrPr@rAs@r,rCrCs I* %F '*%) I:F )>,44;; * 1? ! 3 "" . ..   r+rCc eZdZdZeeZy)%AsyncAdaptFallback_asyncpg_connectionr*N)r&r'r(r#rr!rr*r+r,rrsI . )Fr+rceZdZdZdZGddeZGddeZGddeZGd d eZ Gd d e Z Gd de Z Gdde Z Gdde Z Gdde ZGdde ZGdde ZGddeZej&dZej&dZej&dZej.dZdZy )!r_c ||_d|_y)Nnumeric_dollar)r paramstylerUrs r,rz!AsyncAdapt_asyncpg_dbapi.__init__s *r+c \|jdd}|jd|jj}|jdd}|jdd}tj|rt |t ||i|||St|t||i|||S)Nasync_fallbackFasync_creator_fnrRrrS)rRrS) poprconnectrasboolrr!rCr")rUargrEr creator_fnrRrSs r,rz AsyncAdapt_asyncpg_dbapi.connects 0%8VV. 0D0DE (* +S) %(*vv *D( $ ;;~ &8z35"56.K-I  1:s1b12.K-I  r+c eZdZy)AsyncAdapt_asyncpg_dbapi.ErrorNrar*r+r,r`r r+r`c eZdZy) AsyncAdapt_asyncpg_dbapi.WarningNrar*r+r,Warningrrr+rc eZdZy)'AsyncAdapt_asyncpg_dbapi.InterfaceErrorNrar*r+r,InterfaceErrorrrr+rc eZdZy)&AsyncAdapt_asyncpg_dbapi.DatabaseErrorNrar*r+r, DatabaseErrorrrr+rc eZdZy)&AsyncAdapt_asyncpg_dbapi.InternalErrorNrar*r+r, InternalErrorrrr+rc eZdZy))AsyncAdapt_asyncpg_dbapi.OperationalErrorNrar*r+r,OperationalErrorrrr+rc eZdZy))AsyncAdapt_asyncpg_dbapi.ProgrammingErrorNrar*r+r,ProgrammingErrorrrr+rc eZdZy)'AsyncAdapt_asyncpg_dbapi.IntegrityErrorNrar*r+r,IntegrityErrorrrr+rc eZdZy)"AsyncAdapt_asyncpg_dbapi.DataErrorNrar*r+r, DataErrorrrr+rc eZdZy)*AsyncAdapt_asyncpg_dbapi.NotSupportedErrorNrar*r+r,NotSupportedErrorrrr+rc eZdZy),AsyncAdapt_asyncpg_dbapi.InternalServerErrorNrar*r+r,rrrr+rceZdZfdZxZS)4AsyncAdapt_asyncpg_dbapi.InvalidCachedStatementErrorc*t||dzy)Nzc (SQLAlchemy asyncpg dialect will now invalidate all prepared caches in response to this exception))r)r)rUmessager*s r,rz=AsyncAdapt_asyncpg_dbapi.InvalidCachedStatementError.__init__s G EE r+)r&r'r(rr@rAs@r,rrs   r+rSTRINGNUMBERDATETIMEc ddl}|jj|j|jj|j |jj |j|jj|j|jj|j|jj|jiS)Nr) r exceptions!IntegrityConstraintViolationErrorrrr`SyntaxOrAccessErrorrrrrrs r,raz1AsyncAdapt_asyncpg_dbapi._asyncpg_error_translates    @ @$BUBU    , ,djj    2 2D4I4I    - -t/B/B    : :D<\<\    2 2D4L4L   r+c|SrSr*rls r,BinaryzAsyncAdapt_asyncpg_dbapi.Binarys r+N)r&r'r(rrrr`rrrrrrrrrrrrsymbolrrrmemoized_propertyrarr*r+r,r_r_s+2   )        =  =    M  M  m &7T[[ "F T[[ "Ft{{:&H     r+r_c eZdZdZdZdZdZdZdZdZ e Z e Z eZej"ej&iej*eej.eeeeeeeej<eej@e!ejDe#ejHe%e&e%ejNe(ejRe*ejVe,ejZe.ej^e0ejbe2ejfe4ejje6e7jpe9ejfjte;ejfjxe=ejfj|e?ejfjeAejeCeDeEeFeGejeIeJjeLeJjeNi ZdZOdZPdZQejdZSeTdZUejd ZVd ZWd ZXdd ZYd ZZdZ[dZ\dZ]ddZ^dZ_dZ`eTdZadZbdZcdZddZefdZfdZgxZhS)PGDialect_asyncpgrTrFrc6tj|_yrS)rMrrs r,rz*PGDialect_asyncpg._invalidate_schema_cache3s-1YY[*r+c|jr`t|jdrJttjd|jj Dcgc] }t |c}Sycc}w)N __version__z(\d+)(?:[-\.]?|$))crr)rhasattrtuplerfindallrr)rUxs r,_dbapi_versionz PGDialect_asyncpg._dbapi_version6sa ::'$**m< ZZ,djj.D.DF  sA.c*ttdS)Nr)r_ __import__)rCs r, import_dbapizPGDialect_asyncpg.import_dbapiDs' 9(=>>r+cdddddS)Nrjread_committedrepeatable_read serializable) AUTOCOMMITzREAD COMMITTEDzREPEATABLE READ SERIALIZABLEr*rs r,_isolation_lookupz#PGDialect_asyncpg._isolation_lookupHs'.0*   r+c,t|jSrS)rrrUdbapi_connections r,get_isolation_level_valuesz,PGDialect_asyncpg.get_isolation_level_valuesQsD**++r+c@|j|j|yrS)ryr)rUrrxs r,ryz%PGDialect_asyncpg.set_isolation_levelTs,,T-C-CE-JKr+c,t|jSrS)rrj)rU dbapi_conns r,detect_autocommit_settingz+PGDialect_asyncpg.detect_autocommit_settingWsJ))**r+c||_yrSrFrUrQrss r, set_readonlyzPGDialect_asyncpg.set_readonlyZs # r+c|jSrSrrUrQs r, get_readonlyzPGDialect_asyncpg.get_readonly]s"""r+c||_yrSrGrs r,set_deferrablez PGDialect_asyncpg.set_deferrable`s % r+c|jSrSrrs r,get_deferrablez PGDialect_asyncpg.get_deferrablecs$$$r+c$|jyrS)rrs r, do_terminatezPGDialect_asyncpg.do_terminatefs""$r+c|jd}|j|\}}|j|j|r|sJt |dk(r|d|d<|d|d|d<nxt |st jdt |st jdt||d<t||d<ntj|dttj|d tg|fS) Nuser)usernamerrhostportzBAll hosts are required to be present for asyncpg multiple host URLzBAll ports are required to be present for asyncpg multiple host URLrR) translate_connect_args_split_multihost_from_urlupdatequeryrallr ArgumentErrorrrcoerce_kw_typer)rUurlopts multihosts multiportss r,create_connect_argsz%PGDialect_asyncpg.create_connect_argsis))6):!%!?!?!D J CII  ::!#)!}V a=,#-a=DL_''5_''5 $J/V #J/V   fc 2 D"A3GDzr+c$|jy)NT)rors r,do_pingzPGDialect_asyncpg.do_pingsr+c|jjdd}tj|rtj Stj S)NrF)rgetrrrFallbackAsyncAdaptedQueuePoolAsyncAdaptedQueuePool)rCr rs r,get_pool_classz PGDialect_asyncpg.get_pool_classs;'7? ;;~ &55 5-- -r+c|r|jjSt||jjxr dt |vS)Nzconnection is closed)rr^rqrrrr)rUrrQrs r, is_disconnectzPGDialect_asyncpg.is_disconnectsG ))335 54::,,3(CF2 3r+cK|j}|jxstjfd}|j dt j |ddd{y7w)zset up JSON codec for asyncpg. This occurs for all new connections and can be overridden by third party dialects. .. versionadded:: 1.4.27 c0|jSrSdecode bin_value deserializers r, _json_decoderzAPGDialect_asyncpg.setup_asyncpg_json_codec.._json_decoders 0 0 23 3r+r pg_catalogbinaryencoderdecoderschemaformatN)r_json_deserializer_py_jsonloadsset_type_codecrrencode)rUconnasyncpg_connectionr rs @r,setup_asyncpg_json_codecz*PGDialect_asyncpg.setup_asyncpg_json_codecs`"--..@(..  4!// JJ! 0   sAA"A A"cK|j}|jxstjd}|jxstjfd}|j d||ddd{y7w)zset up JSONB codec for asyncpg. This occurs for all new connections and can be overridden by third party dialects. .. versionadded:: 1.4.27 c(d|jzS)N)r,) str_values r,_jsonb_encoderzCPGDialect_asyncpg.setup_asyncpg_jsonb_codec.._jsonb_encodersY--// /r+c6|ddjS)Nrrrs r,_jsonb_decoderzCPGDialect_asyncpg.setup_asyncpg_jsonb_codec.._jsonb_decoders !" 4 4 67 7r+jsonbr!r"r#N)rr(r)r*r+)rUr-r.r4r6rs @r,setup_asyncpg_jsonb_codecz+PGDialect_asyncpg.setup_asyncpg_jsonb_codecsw"--..@(..  0 ..@(..  8 !// "" 0   sA*A5-A3.A5cK|j}|jdddddd{|jddd ddd{y7%7w) Ninetc|SrSr*ss r,z@PGDialect_asyncpg._disable_asyncpg_inet_codecs..ar+c|SrSr*r<s r,r>z@PGDialect_asyncpg._disable_asyncpg_inet_codecs..r?r+r!textr#cidrc|SrSr*r<s r,r>z@PGDialect_asyncpg._disable_asyncpg_inet_codecs..r?r+c|SrSr*r<s r,r>z@PGDialect_asyncpg._disable_asyncpg_inet_codecs..r?r+)rr+)rUr-r.s r,_disable_asyncpg_inet_codecsz.PGDialect_asyncpg._disable_asyncpg_inet_codecssw!-- //  0   !//  0     s!(AAA A AAc4tfd}|S)zon_connect for asyncpg A major component of this for asyncpg is to set up type decoders at the asyncpg level. See https://github.com/MagicStack/asyncpg/issues/623 for notes on JSON/JSONB implementation. c|jj||jj|jdur |jj | |yyrL)rr/r8_native_inet_typesrE)r-rU super_connects r,rz-PGDialect_asyncpg.on_connect..connectsi KK55d; < KK66t< =&&%/ D==dCD(d#)r+)r) on_connect)rUrrIr*s` @r,rJzPGDialect_asyncpg.on_connects*,  $r+c|jSrS)rrs r,get_driver_connectionz'PGDialect_asyncpg.get_driver_connections%%%r+)r!rr )ir&r'r(driversupports_statement_cachesupports_server_side_cursorsr) has_terminatedefault_paramstylesupports_sane_multi_rowcountrexecution_ctx_clsrstatement_compilerrpreparerr update_copyrcolspecsrStringr/rr$rr5rrr1Timer3Dater9DateTimer;Intervalr?r Booleanr=IntegerrK SmallIntegerrM BigIntegerrONumericryFloatrJSONrQ LargeBinaryr7rJSONBr] JSONPathTyperm JSONIndexTyper`JSONIntIndexTyperdJSONStrIndexTyperjEnumrIrrrrCHARrrAbstractSingleRangerAbstractMultiRangeris_asyncrrrrrGrrrryrrrrrrrrrrr/r8rErJrLr@rAs@r,rrs F##' M)#( 2++Ht OO] NNL    F  '  MM;   MM;          o    n    n   ! !#6    !2    n NNL! " MM;# $  , JJ MM & &(; MM ' ')= MM * *,C MM * *,C MM;  o MM;  & &  % %'9; !HDH$%!9     ??   ,L+$#&%%<..3 0 B &0&r+r)f__doc__ __future__r collectionsrr~rr)rrMrrarrayrPGARRAYbaser r r r r rrrrrrrtypesrrrrrrconnectors.asynciorenginerrsqlrutil.concurrencyr r!r"r$rXr/r1rYr3r5r7rZr9r[r;r]r=r?rIr^rKr_rMr`rOrcrQrer]rgr`rhrdrirjrfrmraryrbrrrrkrAbstractSingleRangeImplrAbstractMultiRangeImplrrrrrr&rCrr_rrVr*r+r,r|shT# # $&6' '.*7HOOy(--5(--h''X%%DhD$X%%(//++$)) 4::  8==66 hmm<< hmm<< $++  X%%>>8>> h(--F22B,66,^?!3?4   #7 HHVL #<L ^^$8:K^B*,I* ZZzB& B&J r+