1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
U
¸ý°d£'ã@sÐdZddlmZddlmZddlmZddlmZddlm    Z    dd    l
m Z dd
l
m Z dd l
m Z Gd d „d ƒZGdd„deƒZGdd„de    ƒZGdd„deƒZdd„ZGdd„dƒZGdd„deƒZeZdS)a\
.. dialect:: mysql+asyncmy
    :name: asyncmy
    :dbapi: asyncmy
    :connectstring: mysql+asyncmy://user:password@host:port/dbname[?key=value&key=value...]
    :url: https://github.com/long2ice/asyncmy
 
.. note:: The asyncmy dialect as of September, 2021 was added to provide
   MySQL/MariaDB asyncio compatibility given that the :ref:`aiomysql` database
   driver has become unmaintained, however asyncmy is itself very new.
 
Using a special asyncio mediation layer, the asyncmy 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("mysql+asyncmy://user:pass@hostname/dbname?charset=utf8mb4")
 
 
é)Úasynccontextmanageré)ÚMySQLDialect_pymysqlé)Úpool)Úutil)ÚAdaptedConnection)Úasyncio)Úawait_fallback)Ú
await_onlyc@s®eZdZdZdZdd„Zedd„ƒZedd„ƒZed    d
„ƒZ    e    j
d d
„ƒZ    ed d „ƒZ dd„Z d#dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd$dd „Zd!d"„ZdS)%ÚAsyncAdapt_asyncmy_cursorF)Ú_adapt_connectionÚ _connectionÚawait_Ú_cursorÚ_rowscCs:||_|j|_|j|_|j ¡}| | ¡¡|_g|_dS©N)r rrÚcursorÚ
__aenter__rr©ÚselfZadapt_connectionr©rúXd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/dialects/mysql/asyncmy.pyÚ__init__6s 
z"AsyncAdapt_asyncmy_cursor.__init__cCs|jjSr)rÚ description©rrrrr@sz%AsyncAdapt_asyncmy_cursor.descriptioncCs|jjSr)rÚrowcountrrrrrDsz"AsyncAdapt_asyncmy_cursor.rowcountcCs|jjSr©rÚ    arraysizerrrrrHsz#AsyncAdapt_asyncmy_cursor.arraysizecCs ||j_dSrr©rÚvaluerrrrLscCs|jjSr)rÚ    lastrowidrrrrr!Psz#AsyncAdapt_asyncmy_cursor.lastrowidcCsg|jdd…<dSr©rrrrrÚcloseTszAsyncAdapt_asyncmy_cursor.closeNcCs| | ||¡¡Sr)rÚ_execute_async)rÚ    operationÚ
parametersrrrÚexecute^sz!AsyncAdapt_asyncmy_cursor.executecCs| | ||¡¡Sr)rÚ_executemany_async©rr%Zseq_of_parametersrrrÚ executemanyas
ÿz%AsyncAdapt_asyncmy_cursor.executemanyc Ãs†|j ¡4IdHšd|dkr0|j |¡IdH}n|j ||¡IdH}|js`t|j ¡IdHƒ|_|W5QIdHR£SQIdHRXdSr)r Ú_mutex_and_adapt_errorsrr'Ú server_sideÚlistÚfetchallr)rr%r&Úresultrrrr$fsz(AsyncAdapt_asyncmy_cursor._execute_asyncc ÃsJ|j ¡4IdHš(|j ||¡IdHW5QIdHR£SQIdHRXdSr)r r+rr*r)rrrr(usz,AsyncAdapt_asyncmy_cursor._executemany_asynccGsdSrr)rZ
inputsizesrrrÚ setinputsizesysz'AsyncAdapt_asyncmy_cursor.setinputsizesccs|jr|j d¡VqdS©Nr©rÚpoprrrrÚ__iter__|sz"AsyncAdapt_asyncmy_cursor.__iter__cCs|jr|j d¡SdSdSr1r2rrrrÚfetchone€s z"AsyncAdapt_asyncmy_cursor.fetchonecCs8|dkr|j}|jd|…}|j|d…|jdd…<|Sr1)rr)rÚsizeÚretvalrrrÚ    fetchmany†s
z#AsyncAdapt_asyncmy_cursor.fetchmanycCs |jdd…}g|jdd…<|Srr")rr7rrrr.Žsz"AsyncAdapt_asyncmy_cursor.fetchall)N)N)Ú__name__Ú
__module__Ú __qualname__r,Ú    __slots__rÚpropertyrrrÚsetterr!r#r'r*r$r(r0r4r5r8r.rrrrr ,s.
 
 
 
 
 
 
 
 
r c@s>eZdZdZdZdd„Zdd„Zdd„Zdd
d „Zd d „Z    d    S)ÚAsyncAdapt_asyncmy_ss_cursorrTcCs>||_|j|_|j|_|j |jjjj¡}| | ¡¡|_    dSr)
r rrrÚdbapiÚasyncmyZcursorsZSSCursorrrrrrrr˜s
ÿz%AsyncAdapt_asyncmy_ss_cursor.__init__cCs$|jdk    r | |j ¡¡d|_dSr)rrr#rrrrr#£s
z"AsyncAdapt_asyncmy_ss_cursor.closecCs| |j ¡¡Sr)rrr5rrrrr5¨sz%AsyncAdapt_asyncmy_ss_cursor.fetchoneNcCs| |jj|d¡S)N)r6)rrr8)rr6rrrr8«sz&AsyncAdapt_asyncmy_ss_cursor.fetchmanycCs| |j ¡¡Sr)rrr.rrrrr.®sz%AsyncAdapt_asyncmy_ss_cursor.fetchall)N)
r9r:r;r<r,rr#r5r8r.rrrrr?”s 
r?c@sneZdZeeƒZdZdd„Zedd„ƒZ    dd„Z
dd    „Z d
d „Z d d „Z ddd„Zdd„Zdd„Zdd„ZdS)ÚAsyncAdapt_asyncmy_connection)r@Ú_execute_mutexcCs||_||_t ¡|_dSr)r@rr    ÚLockrC)rr@Ú
connectionrrrr¶sz&AsyncAdapt_asyncmy_connection.__init__c
CsP|j4IdHš2z
dVWn tk
r:|j d¡‚YnXW5QIdHRXdS)Nz7network operation failed due to asyncmy attribute error)rCÚAttributeErrorr@Ú InternalErrorrrrrr+»s
ÿz5AsyncAdapt_asyncmy_connection._mutex_and_adapt_errorscCs|rt‚| | ¡¡Sr)ÚAssertionErrorrÚ_do_ping)rZ    reconnectrrrÚpingÅsz"AsyncAdapt_asyncmy_connection.pingc ÃsF| ¡4IdHš&|j d¡IdHW5QIdHR£SQIdHRXdS)NF)r+rrJrrrrrIÉsz&AsyncAdapt_asyncmy_connection._do_pingcCs
|j ¡Sr)rÚcharacter_set_namerrrrrKÍsz0AsyncAdapt_asyncmy_connection.character_set_namecCs| |j |¡¡dSr)rrÚ
autocommitrrrrrLÐsz(AsyncAdapt_asyncmy_connection.autocommitFcCs|r t|ƒSt|ƒSdSr)r?r )rr,rrrrÓsz$AsyncAdapt_asyncmy_connection.cursorcCs| |j ¡¡dSr)rrÚrollbackrrrrrMÙsz&AsyncAdapt_asyncmy_connection.rollbackcCs| |j ¡¡dSr)rrÚcommitrrrrrNÜsz$AsyncAdapt_asyncmy_connection.commitcCs|j ¡dSr)rr#rrrrr#ßsz#AsyncAdapt_asyncmy_connection.closeN)F)r9r:r;Ú staticmethodr rr<rrr+rJrIrKrLrrMrNr#rrrrrB²s
    
rBc@seZdZdZeeƒZdS)Ú%AsyncAdaptFallback_asyncmy_connectionrN)r9r:r;r<rOr
rrrrrrPäsrPcCst|ƒS)zReturn x as a binary type.)Úbytes)ÚxrrrÚ_BinaryêsrSc@s^eZdZdd„Zdd„Ze d¡Ze d¡Ze d¡Z    e d¡Z
e d    ¡Z e e ƒZd
d „Zd S) ÚAsyncAdapt_asyncmy_dbapicCs||_d|_| ¡dS)NÚformat)rAZ
paramstyleÚ_init_dbapi_attributes)rrArrrrðsz!AsyncAdapt_asyncmy_dbapi.__init__cCs$dD]}t||t|jj|ƒƒqdS)N) ÚWarningÚErrorÚInterfaceErrorZ    DataErrorZ DatabaseErrorZOperationalErrorrYZIntegrityErrorZProgrammingErrorrGZNotSupportedError)ÚsetattrÚgetattrrAÚerrors)rÚnamerrrrVõs z/AsyncAdapt_asyncmy_dbapi._init_dbapi_attributesÚSTRINGÚNUMBERÚBINARYÚDATETIMEÚ    TIMESTAMPcOsJ| dd¡}t |¡r.t|t|jj||ŽƒƒSt|t|jj||ŽƒƒSdS©NÚasync_fallbackF)    r3rÚasboolrPr
rAÚconnectrBr )rÚargÚkwrdrrrrf s 
þþz AsyncAdapt_asyncmy_dbapi.connectN)r9r:r;rrVrÚsymbolr^r_r`rarbrOrSÚBinaryrfrrrrrTïs
 
 
 
 
rTcsdeZdZdZdZdZeZdZe    dd„ƒZ
e    dd„ƒZ ‡fdd„Z ‡fd    d
„Z d d „Zd d„Z‡ZS)ÚMySQLDialect_asyncmyrATcCs ttdƒƒS)NrA)rTÚ
__import__)ÚclsrrrÚ import_dbapi$sz!MySQLDialect_asyncmy.import_dbapicCs(|j dd¡}t |¡rtjStjSdSrc)ÚqueryÚgetrrerZFallbackAsyncAdaptedQueuePoolZAsyncAdaptedQueuePool)rmÚurlrdrrrÚget_pool_class(s
z#MySQLDialect_asyncmy.get_pool_classcstƒj|tddddS)NÚuserÚdb)ÚusernameZdatabase)Z_translate_args)ÚsuperÚcreate_connect_argsÚdict)rrq©Ú    __class__rrrw2s
ÿz(MySQLDialect_asyncmy.create_connect_argscs4tƒ |||¡rdSt|ƒ ¡}d|kp.d|kSdS)NTz not connectedznetwork operation failed)rvÚ is_disconnectÚstrÚlower)rÚerErZstr_eryrrr{7s
 ÿz"MySQLDialect_asyncmy.is_disconnectcCsddlm}|jS)Nr)ÚCLIENT)Zasyncmy.constantsrZ
FOUND_ROWS)rrrrrÚ_found_rows_client_flag@s z,MySQLDialect_asyncmy._found_rows_client_flagcCs|jSr)r)rrErrrÚget_driver_connectionEsz*MySQLDialect_asyncmy.get_driver_connection)r9r:r;ZdriverZsupports_statement_cacheZsupports_server_side_cursorsr?Z    _sscursorZis_asyncÚ classmethodrnrrrwr{r€rÚ __classcell__rrryrrks
 
          rkN)Ú__doc__Ú
contextlibrZpymysqlrÚrrZenginerZutil.concurrencyr    r
r r r?rBrPrSrTrkÚdialectrrrrÚ<module>    s         h2,.