U a$@sdZddlZddlZddlZddlZddlZddlmZddlm Z ddlm Z ddlm Z ddlm Z dd lm Z dd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZzddlmZ Wne!k rRdZ YnXGdddej"Z#Gdddej$Z%Gdddej&Z'Gd d!d!ej(Z)Gd"d#d#e Z*Gd$d%d%e Z+Gd&d'd'ej,Z-Gd(d)d)ej.Z/Gd*d+d+ej0Z1Gd,d-d-ej2Z3Gd.d/d/ej0j4Z5Gd0d1d1ej0j6Z7Gd2d3d3ej0j8Z9Gd4d5d5ej:Z;Gd6d7d7eZGd:d;d;eZ?Gdd?d?eZAGd@dAdAeZBGdBdCdCeZCGdDdEdEZDGdFdGdGeDZEGdHdIdIZFGdJdKdKeFZGGdLdMdMZHeHjIdNeHjJdOeHjKdPeHjLdQeHjMdReHj dSeHjNdTeHjOdUeHjPdVeHjQdWeHjRdXeHjSdYeHjTdZeHj0d[eHj2d\eHj d]eHjd^eHjUd_iZVGd`dadaeZWeWZXdS)ba .. 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") The dialect can also be run as a "synchronous" dialect within the :func:`_sa.create_engine` function, which will pass "await" calls into an ad-hoc event loop. This mode of operation is of **limited use** and is for special testing scenarios only. The mode can be enabled by adding the SQLAlchemy-specific flag ``async_fallback`` to the URL in conjunction with :func:`_sa.create_engine`:: # for testing purposes only; do not use in production! engine = create_engine("postgresql+asyncpg://user:pass@hostname/dbname?async_fallback=true") .. 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_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. N)json)_DECIMAL_TYPES) _FLOAT_TYPES) _INT_TYPESENUMINTERVAL)OID) PGCompiler) PGDialect)PGExecutionContext)PGIdentifierPreparer)REGCLASSUUID)exc)pool) processors)util)sqltypes)asyncio)await_fallback) await_onlyc@seZdZddZdS) AsyncpgTimecCs|jSN)TIMEselfdbapir"gC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\dialects\postgresql\asyncpg.pyget_dbapi_typeszAsyncpgTime.get_dbapi_typeN__name__ __module__ __qualname__r$r"r"r"r#rsrc@seZdZddZdS) AsyncpgDatecCs|jSr)DATErr"r"r#r$szAsyncpgDate.get_dbapi_typeNr%r"r"r"r#r)sr)c@seZdZddZdS)AsyncpgDateTimecCs|jr |jS|jSdSr)timezoneTIMESTAMP_W_TZ TIMESTAMPrr"r"r#r$szAsyncpgDateTime.get_dbapi_typeNr%r"r"r"r#r+sr+c@seZdZddZdS)AsyncpgBooleancCs|jSr)BOOLEANrr"r"r#r$szAsyncpgBoolean.get_dbapi_typeNr%r"r"r"r#r/sr/c@s eZdZddZeddZdS)AsyncPgIntervalcCs|jSrr rr"r"r#r$szAsyncPgInterval.get_dbapi_typecKs t|jdS)N)Z precision)r1Zsecond_precision)clsintervalkwr"r"r#adapt_emulated_to_nativesz(AsyncPgInterval.adapt_emulated_to_nativeN)r&r'r(r$ classmethodr5r"r"r"r#r1sr1c@seZdZddZdS) AsyncPgEnumcCs|jSrrrr"r"r#r$szAsyncPgEnum.get_dbapi_typeNr%r"r"r"r#r7sr7c@seZdZddZdS)AsyncpgIntegercCs|jSrINTEGERrr"r"r#r$szAsyncpgInteger.get_dbapi_typeNr%r"r"r"r#r8sr8c@seZdZddZdS)AsyncpgBigIntegercCs|jSr) BIGINTEGERrr"r"r#r$sz AsyncpgBigInteger.get_dbapi_typeNr%r"r"r"r#r;sr;c@seZdZddZddZdS) AsyncpgJSONcCs|jSr)JSONrr"r"r#r$szAsyncpgJSON.get_dbapi_typecCsdSrr"r dialectcoltyper"r"r#result_processorszAsyncpgJSON.result_processorNr&r'r(r$rBr"r"r"r#r=sr=c@seZdZddZddZdS) AsyncpgJSONBcCs|jSr)JSONBrr"r"r#r$szAsyncpgJSONB.get_dbapi_typecCsdSrr"r?r"r"r#rBszAsyncpgJSONB.result_processorNrCr"r"r"r#rDsrDc@seZdZddZdS)AsyncpgJSONIndexTypecCs tddS)Nzshould not be hereNotImplementedErrorrr"r"r#r$sz#AsyncpgJSONIndexType.get_dbapi_typeNr%r"r"r"r#rFsrFc@seZdZddZdS)AsyncpgJSONIntIndexTypecCs|jSrr9rr"r"r#r$sz&AsyncpgJSONIntIndexType.get_dbapi_typeNr%r"r"r"r#rIsrIc@seZdZddZdS)AsyncpgJSONStrIndexTypecCs|jSrSTRINGrr"r"r#r$sz&AsyncpgJSONStrIndexType.get_dbapi_typeNr%r"r"r"r#rJsrJc@seZdZddZdS)AsyncpgJSONPathTypecCs dd}|S)NcSs$t|tjjstdd|D}|S)NcSsg|]}t|qSr")r text_type).0elemr"r"r# szGAsyncpgJSONPathType.bind_processor..process..) isinstancercollections_abcSequenceAssertionError)valuetokensr"r"r#processsz3AsyncpgJSONPathType.bind_processor..processr"r r@rXr"r"r#bind_processorsz"AsyncpgJSONPathType.bind_processorN)r&r'r(rZr"r"r"r#rMsrMc@s$eZdZddZddZddZdS) AsyncpgUUIDcCs|jSrrrr"r"r#r$szAsyncpgUUID.get_dbapi_typecCs|js|jrdd}|SdS)NcSs|dk rt|}|Sr) _python_UUIDrVr"r"r#rXsz+AsyncpgUUID.bind_processor..processZas_uuiduse_native_uuidrYr"r"r#rZs zAsyncpgUUID.bind_processorcCs|js|jrdd}|SdS)NcSs|dk rt|}|Sr)strr]r"r"r#rXsz-AsyncpgUUID.result_processor..processr^)r r@rArXr"r"r#rBs zAsyncpgUUID.result_processorN)r&r'r(r$rZrBr"r"r"r#r[s r[c@seZdZddZddZdS)AsyncpgNumericcCsdSrr")r r@r"r"r#rZszAsyncpgNumeric.bind_processorcCsv|jrB|tkrttj|jS|tks.|tkr2dSt d|n0|tkrNdS|tks^|tkrdtj St d|dS)NzUnknown PG numeric type: %d) Z asdecimalrrZto_decimal_processor_factorydecimalDecimalZ_effective_decimal_return_scalerrrZInvalidRequestErrorZto_floatr?r"r"r#rBs$zAsyncpgNumeric.result_processorN)r&r'r(rZrBr"r"r"r#rasrac@seZdZddZdS)AsyncpgREGCLASScCs|jSrrKrr"r"r#r$szAsyncpgREGCLASS.get_dbapi_typeNr%r"r"r"r#rdsrdc@seZdZddZdS) AsyncpgOIDcCs|jSrr9rr"r"r#r$szAsyncpgOID.get_dbapi_typeNr%r"r"r"r#resrec@s$eZdZddZddZddZdS)PGExecutionContext_asyncpgcCs(t||jjj|jjjfr$|jdSr)rRr@r!InvalidCachedStatementErrorInternalServerError_invalidate_schema_cache)r er"r"r#handle_dbapi_exception"sz1PGExecutionContext_asyncpg.handle_dbapi_exceptioncCs4|jr|j|jj|j_|js&dStjh|_dSr) Zisddlr@ri_invalidate_schema_cache_asofcursorZcompiledAsyncAdapt_asyncpg_dbapirZexclude_set_input_sizesr r"r"r#pre_exec,s z#PGExecutionContext_asyncpg.pre_execcCs|jjddS)NT) server_side)Z_dbapi_connectionrmror"r"r#create_server_side_cursor<sz4PGExecutionContext_asyncpg.create_server_side_cursorN)r&r'r(rkrprrr"r"r"r#rf!s rfc@s eZdZdS)PGCompiler_asyncpgNr&r'r(r"r"r"r#rs@srsc@s eZdZdS)PGIdentifierPreparer_asyncpgNrtr"r"r"r#ruDsruc@seZdZdZdZddZddZddZd d Zd d Z d dZ dddZ ddZ ddZ ddZddZdddZddZdS) AsyncAdapt_asyncpg_cursor) _adapt_connection _connection_rows description arraysizerowcount _inputsizes_cursorrlFcCs<||_|j|_g|_d|_d|_d|_d|_d|_d|_dS)Nrr) rwrxryr~rzr{r|r}rlr adapt_connectionr"r"r#__init__Wsz"AsyncAdapt_asyncpg_cursor.__init__cCsg|jdd<dSrryror"r"r#closebszAsyncAdapt_asyncpg_cursor.closecCs|j|dSr)rw_handle_exceptionr errorr"r"r#resz+AsyncAdapt_asyncpg_cursor._handle_exceptioncCsF|jstddt|dDStddtdd|jDdDSdS)Ncss|]\}}d|VqdS)$%dNr")rOidx_r"r"r# jszDAsyncAdapt_asyncpg_cursor._parameter_placeholders..rcss*|]"\}}|rd||fnd|VqdS)z$%d::%srNr")rOrtypr"r"r#rmscss|]}t|VqdSr) _pg_typesget)rOrr"r"r#rps)r}tuple enumerate)r paramsr"r"r#_parameter_placeholdershsz1AsyncAdapt_asyncpg_cursor._parameter_placeholdersc s&|j}|j4IdH|js,|IdH|dk rD|||}nd}z|||jIdH\}}|rxdd|D|_nd|_|jr|j |IdH|_ d|_ nB|j |IdH|_ |}td|}|rt|d|_ nd|_ Wn.tk r}z||W5d}~XYnXW5QIdHRXdS)Nr"c Ss$g|]}|j|jjdddddfqSr)nametypeoid)rOattrr"r"r#rQs zBAsyncAdapt_asyncpg_cursor._prepare_and_execute..rz"(?:UPDATE|DELETE|INSERT \d+) (\d+)r)rw_execute_mutex_started_start_transactionr_preparerlrzrqrmr~r|fetchryZ get_statusmsgrematchintgroup Exceptionr) r operation parametersr prepared_stmt attributesstatusregrr"r"r#_prepare_and_executetsB   z.AsyncAdapt_asyncpg_cursor._prepare_and_executec s|j}|j4IdH||jIdH|js<|IdH|||d}z(|j||IdHWW5QIdHRSt k r}z| |W5d}~XYnXW5QIdHRXdSNr) rwr_check_type_cache_invalidationrlrrrrx executemanyrr)r rseq_of_parametersrrr"r"r# _executemanys" z&AsyncAdapt_asyncpg_cursor._executemanyNcCs|j|||dSr)rwawait_r)r rrr"r"r#executes z!AsyncAdapt_asyncpg_cursor.executecCs|j|||Sr)rwrrr rrr"r"r#rs z%AsyncAdapt_asyncpg_cursor.executemanycGs ||_dSr)r})r Z inputsizesr"r"r# setinputsizessz'AsyncAdapt_asyncpg_cursor.setinputsizesccs|jr|jdVqdSrrypopror"r"r#__iter__sz"AsyncAdapt_asyncpg_cursor.__iter__cCs|jr|jdSdSdSrrror"r"r#fetchones z"AsyncAdapt_asyncpg_cursor.fetchonecCs8|dkr|j}|jd|}|j|d|jdd<|Sr)r{ry)r sizeretvalr"r"r# fetchmanys z#AsyncAdapt_asyncpg_cursor.fetchmanycCs |jdd}g|jdd<|Srr)r rr"r"r#fetchallsz"AsyncAdapt_asyncpg_cursor.fetchall)N)N)r&r'r( __slots__rqrrrrrrrrrrrrrr"r"r"r#rvHs   6  rvcsneZdZdZdZfddZddZddZd d Zd d Z d dZ dddZ ddZ ddZ ddZZS)AsyncAdapt_asyncpg_ss_cursorT) _rowbuffercstt||d|_dSr)superrrrr __class__r"r#rsz%AsyncAdapt_asyncpg_ss_cursor.__init__cCsd|_d|_dSr)r~rror"r"r#rsz"AsyncAdapt_asyncpg_ss_cursor.closecCs$|j|jd}t||_dS)N2)rwrr~r collectionsdequer)r Znew_rowsr"r"r# _buffer_rowssz)AsyncAdapt_asyncpg_ss_cursor._buffer_rowscCs|Srr"ror"r"r# __aiter__sz&AsyncAdapt_asyncpg_ss_cursor.__aiter__cCs8|js||jr"|jVq||jsq4qdSrrrpopleftror"r"r# __anext__sz&AsyncAdapt_asyncpg_ss_cursor.__anext__cCs"|js||jsdS|jSrrror"r"r#rs z%AsyncAdapt_asyncpg_ss_cursor.fetchoneNcCsz|dkr|S|js|t|j}t|}||krV||j|j |||d|}t ||d|_|Sr) rrrlistlenextendrwrr~rrr)r rbufZlbresultr"r"r#r s  z&AsyncAdapt_asyncpg_ss_cursor.fetchmanycCs,t|jt|j|}|j|Sr)rrrwr_allclear)r retr"r"r#rs   z%AsyncAdapt_asyncpg_ss_cursor.fetchallcs0g}|jdIdH}|r,||qqq,q|S)Ni)r~rr)r rowsbatchr"r"r#r%s z!AsyncAdapt_asyncpg_ss_cursor._allcCs tddS)Nz2server side cursor doesn't support executemany yetrGrr"r"r#r3sz(AsyncAdapt_asyncpg_ss_cursor.executemany)N)r&r'r(rqrrrrrrrrrrr __classcell__r"r"rr#rs   rc@seZdZdZeeZdddZddZddZ d d Z e d d Z e j d d Z ddZddZdddZddZddZddZdS)AsyncAdapt_asyncpg_connection) r!rxisolation_level_isolation_settingreadonly deferrable _transactionr_prepared_statement_cacherlrdcCs`||_||_d|_|_d|_d|_d|_d|_t|_ t |_ |rVt ||_nd|_dS)Nread_committedF)r!rxrrrrrrtimerlrLockrrZLRUCacher)r r! connectionprepared_statement_cache_sizer"r"r#rJs   z&AsyncAdapt_asyncpg_connection.__init__cs$||jkr |jIdH||_dSr)rlrxZreload_schema_state)r invalidate_timestampr"r"r#r\s z}||kr4||dt ||f}t |dd|_ |_ ||q4|n|dS)NFz%s: %ssqlstate)rx is_closedrrrRrnErrorr!_asyncpg_error_translater__mro__getattrZpgcoder)r rZexception_mappingZsuper_Ztranslated_errorr"r"r#r|s    z/AsyncAdapt_asyncpg_connection._handle_exceptioncCs |jdkSN autocommit)rror"r"r#rsz(AsyncAdapt_asyncpg_connection.autocommitcCs|r d|_n|j|_dSr)rrr rVr"r"r#rscCs|jr|||_|_dSr)rrollbackrr)r levelr"r"r#set_isolation_levelsz1AsyncAdapt_asyncpg_connection.set_isolation_levelc st|jdkrdSz.|jj|j|j|jd|_|jIdHWn,tk rh}z||W5d}~XYnXd|_ dS)Nr)Z isolationrrT) rrxZ transactionrrrstartrrrrr"r"r#rs z0AsyncAdapt_asyncpg_connection._start_transactionFcCs|r t|St|SdSr)rrv)r rqr"r"r#rmsz$AsyncAdapt_asyncpg_connection.cursorc Cs`|jr\zFz||jWn,tk rH}z||W5d}~XYnXW5d|_d|_XdSNF)rrrrrrrr"r"r#rs z&AsyncAdapt_asyncpg_connection.rollbackc Cs`|jr\zFz||jWn,tk rH}z||W5d}~XYnXW5d|_d|_XdSr)rrrcommitrrrr"r"r#rs z$AsyncAdapt_asyncpg_connection.commitcCs|||jdSr)rrrxrror"r"r#rsz#AsyncAdapt_asyncpg_connection.closeN)r)F)r&r'r(r staticmethodrrrrrrpropertyrsetterrrrmrrrr"r"r"r#r9s       rc@seZdZdZeeZdS)%AsyncAdaptFallback_asyncpg_connectionr"N)r&r'r(rrrrr"r"r"r#rsrc@seZdZddZddZGdddeZGdddeZGd d d eZGd d d eZ Gd dde Z Gddde Z Gddde Z Gddde Z Gddde ZGddde ZGddde ZGdddeZejddZdd Zed!Zed"Zed#Zed$Zed%Zed&Zed'Zed(Zed)Zed*Z ed+Z!ed,Z"ed-Z#ed.Z$ed/Z%ed0Z&ed1Z'ed2Z(eZ)e(Z*d3S)4rncCs||_d|_dS)Nformat)asyncpgZ paramstyler rr"r"r#rsz!AsyncAdapt_asyncpg_dbapi.__init__cOs^|dd}|dd}t|r>t|t|jj|||dSt|t|jj|||dSdS)Nasync_fallbackFrr)r) rrasboolrrrconnectrr)r argr4rrr"r"r#rs   z AsyncAdapt_asyncpg_dbapi.connectc@s eZdZdS)zAsyncAdapt_asyncpg_dbapi.ErrorNrtr"r"r"r#rsrc@s eZdZdS)z AsyncAdapt_asyncpg_dbapi.WarningNrtr"r"r"r#Warningsrc@s eZdZdS)z'AsyncAdapt_asyncpg_dbapi.InterfaceErrorNrtr"r"r"r#InterfaceErrorsrc@s eZdZdS)z&AsyncAdapt_asyncpg_dbapi.DatabaseErrorNrtr"r"r"r# DatabaseErrorsrc@s eZdZdS)z&AsyncAdapt_asyncpg_dbapi.InternalErrorNrtr"r"r"r# InternalErrorsrc@s eZdZdS)z)AsyncAdapt_asyncpg_dbapi.OperationalErrorNrtr"r"r"r#OperationalErrorsrc@s eZdZdS)z)AsyncAdapt_asyncpg_dbapi.ProgrammingErrorNrtr"r"r"r#ProgrammingErrorsrc@s eZdZdS)z'AsyncAdapt_asyncpg_dbapi.IntegrityErrorNrtr"r"r"r#IntegrityErrorsrc@s eZdZdS)z"AsyncAdapt_asyncpg_dbapi.DataErrorNrtr"r"r"r# DataErrorsrc@s eZdZdS)z*AsyncAdapt_asyncpg_dbapi.NotSupportedErrorNrtr"r"r"r#NotSupportedError src@s eZdZdS)z,AsyncAdapt_asyncpg_dbapi.InternalServerErrorNrtr"r"r"r#rh srhcseZdZfddZZS)z4AsyncAdapt_asyncpg_dbapi.InvalidCachedStatementErrorcsttj||ddS)Nzc (SQLAlchemy asyncpg dialect will now invalidate all prepared caches in response to this exception))rrnrgr)r messagerr"r#rs z=AsyncAdapt_asyncpg_dbapi.InvalidCachedStatementError.__init__)r&r'r(rrr"r"rr#rgsrgc CsHddl}|jj|j|jj|j|jj|j|jj|j|jj |j |jj |j iSr) r exceptionsZ!IntegrityConstraintViolationErrorrZ PostgresErrorrZSyntaxOrAccessErrorrrrgrhrr"r"r#rsz1AsyncAdapt_asyncpg_dbapi._asyncpg_error_translatecCs|Srr"rr"r"r#Binary&szAsyncAdapt_asyncpg_dbapi.BinaryrLr.r-rr*r NUMBERFLOATr0r:r<BYTESDECIMALr>rErrBYTEAN)+r&r'r(rrrrrrrrrrrrrrhrgrmemoized_propertyrrsymbolrLr.r-rr*r rr r0r:r<r r r>rErrr ZDATETIMEBINARYr"r"r"r#rnsJ                    rnZvarchar timestampztimestamp with time zonedaterr3numericfloatboolintegerZbigintbytesrbrjsonbenumuuidZbyteac)sPeZdZdZdZdZdZdZdZdZ e Z e Z eZdZdZeejejeejeejeejeeee e!ej"e#ej$e%ej&e'ej(e)ej*e+e,j-e.ej*j/e0ej*j1e2ej*j3e4ej*j5e6ej7e8e9e:e;eddZ?ej@dd ZAeBd d ZCej@d d ZDddZEddZFddZGddZHddZIddZJeBddZKddZLddZMfd d!ZNZOS)"PGDialect_asyncpgrTrFrcCst|_dSr)rrlror"r"r#risz*PGDialect_asyncpg._invalidate_schema_cachecCs8|jr0t|jdr0tddtd|jjDSdSdS)N __version__cSsg|] }t|qSr")r)rOxr"r"r#rQsz4PGDialect_asyncpg._dbapi_version..z(\d+)(?:[-\.]?|$))crr)r!hasattrrrfindallrror"r"r#_dbapi_versions z PGDialect_asyncpg._dbapi_versioncCs ttdS)Nr)rn __import__)r2r"r"r#r!szPGDialect_asyncpg.dbapicCsdddddS)NrrZrepeatable_readZ serializable)Z AUTOCOMMITzREAD COMMITTEDzREPEATABLE READZ SERIALIZABLEr"ror"r"r#_isolation_lookups z#PGDialect_asyncpg._isolation_lookupc Cspz|j|dd}WnJtk r`}z,tjtd||jd|jf|dW5d}~XYnX| |dS)Nr zLInvalid value '%s' for isolation_level. Valid isolation levels for %s are %sz, )Zreplace_context) r"replaceKeyErrorrZraise_r ArgumentErrorrjoinr)r rrerrr"r"r#rs z%PGDialect_asyncpg.set_isolation_levelcCs ||_dSrrr rrVr"r"r# set_readonlyszPGDialect_asyncpg.set_readonlycCs|jSrr)r rr"r"r# get_readonlyszPGDialect_asyncpg.get_readonlycCs ||_dSrrr*r"r"r#set_deferrablesz PGDialect_asyncpg.set_deferrablecCs|jSrr.r,r"r"r#get_deferrablesz PGDialect_asyncpg.get_deferrablecCs<|jdd}||jt|dtt|dtg|fS)Nuser)usernamerport)Ztranslate_connect_argsupdatequeryrZcoerce_kw_typer)r urloptsr"r"r#create_connect_argss   z%PGDialect_asyncpg.create_connect_argscCs(|jdd}t|rtjStjSdS)NrF)r5rrrrZFallbackAsyncAdaptedQueuePoolZAsyncAdaptedQueuePool)r2r6rr"r"r#get_pool_classs z PGDialect_asyncpg.get_pool_classcCs,|r|jSt||jjo&dt|kSdS)Nzconnection is closed)rxrrRr!rr`)r rjrrmr"r"r# is_disconnects  zPGDialect_asyncpg.is_disconnectcCs6|jr|jdd|Dn|jfdd|DdS)NcSsg|]\}}}|qSr"r"rOkeyZdbtypeZsqltyper"r"r#rQsz8PGDialect_asyncpg.do_set_input_sizes..cSsi|]\}}}|r||qSr"r"r;r"r"r# sz8PGDialect_asyncpg.do_set_input_sizes..) positionalr)r rmZlist_of_tuplescontextr"r"r#do_set_input_sizess z$PGDialect_asyncpg.do_set_input_sizescs\tt|dd|jp tjfddfddfddfd d }|S) NcSs d|S)N)encode)Z str_valuer"r"r#_jsonb_encodersz4PGDialect_asyncpg.on_connect.._jsonb_encodercs |SrdecodeZ bin_value deserializerr"r# _json_decodersz3PGDialect_asyncpg.on_connect.._json_decodercs|ddS)NrrDrFrGr"r#_jsonb_decodersz4PGDialect_asyncpg.on_connect.._jsonb_decodercs>|jjdtjdddIdH|jjddddIdHdS)aset up type decoders at the asyncpg level. these are set_type_codec() calls to normalize There was a tentative decoder for the "char" datatype here to have it return strings however this type is actually a binary type that other drivers are likely mis-interpreting. See https://github.com/MagicStack/asyncpg/issues/623 for reference on why it's set up this way. rZ pg_catalogbinary)encoderdecoderZschemarNr)rxZset_type_codecr`rBconn)rIrJrCr"r#_setup_type_codecss  z8PGDialect_asyncpg.on_connect.._setup_type_codecscs"||dk r|dSr)rrN)rP super_connectr"r#rsz-PGDialect_asyncpg.on_connect..connect)rr on_connectZ_json_deserializer_py_jsonloads)r rr)rIrJrCrPrHrQr#rRs   zPGDialect_asyncpg.on_connect)Pr&r'r(ZdriverZsupports_statement_cacheZsupports_unicode_statementsZsupports_server_side_cursorsZsupports_unicode_bindsZdefault_paramstyleZsupports_sane_multi_rowcountrfZexecution_ctx_clsrsZstatement_compilerrupreparerZuse_setinputsizesr_rZ update_copyr ZcolspecsrTimerDater)DateTimer+ZIntervalr1r rr[Booleanr/Integerr8 BigIntegerr;Numericrar>r=rrErD JSONPathTyperM JSONIndexTyperFJSONIntIndexTyperIJSONStrIndexTyperJEnumr7r rerrdZis_asyncrlrir r r6r!r"rr+r-r/r0r8r9r:r@rRrr"r"rr#rVs    r)Y__doc__rrbrrSrrbaserrrrr r r r rrrrrrrrZsqlrZutil.concurrencyrrrrr\ ImportErrorrVrrWr)rXr+rYr/r1r7rZr8r[r;r>r=rErDr^rFr_rIr`rJr]rMr[r\rardrerfrsrurvrrrrnrLr.r-r*rrr r0r:r<r r r rrr@r"r"r"r#s^                        TiD