zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
U
¸ý°dc+ã@sàdZddlZddlmZddlmZddlmZddlm    Z    dd    lm
Z
dd
l m Z dd l mZdd l mZGd d„dƒZGdd„deƒZGdd„de ƒZGdd„deƒZGdd„dƒZGdd„deƒZGdd„deƒZeZdS)aZ
 
.. 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`.
 
 
éN)Úpartialé)ÚSQLiteExecutionContext)ÚSQLiteDialect_pysqliteé)Úpool)Úutil)ÚAdaptedConnection)Úawait_fallback)Ú
await_onlyc@s`eZdZdZdZdd„Zdd„Zddd    „Zd
d „Zd d „Z    dd„Z
dd„Z ddd„Z dd„Z dS)ÚAsyncAdapt_aiosqlite_cursor)Ú_adapt_connectionÚ _connectionÚ descriptionÚawait_Ú_rowsÚ    arraysizeÚrowcountÚ    lastrowidFcCs2||_|j|_|j|_d|_d|_d|_g|_dS)Nréÿÿÿÿ)r rrrrrr)ÚselfZadapt_connection©rú[d:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/dialects/sqlite/aiosqlite.pyÚ__init__Lsz$AsyncAdapt_aiosqlite_cursor.__init__cCsg|jdd…<dS©N©r©rrrrÚcloseUsz!AsyncAdapt_aiosqlite_cursor.closeNc
CsØz¤| |j ¡¡}|dkr,| | |¡¡n| | ||¡¡|jrp|j|_d|_|_|js†| | ¡¡|_    nd|_|j|_|j|_|jsœ| | 
¡¡n||_ Wn.t k
rÒ}z|j  |¡W5d}~XYnXdS)Nr)rrÚcursorÚexecuterrrÚ server_sideÚfetchallrrÚ_cursorÚ    Exceptionr Ú_handle_exception)rÚ    operationÚ
parametersr"ÚerrorrrrrXs$ 
z#AsyncAdapt_aiosqlite_cursor.executec
Cs~zJ| |j ¡¡}| | ||¡¡d|_|j|_|j|_| | ¡¡Wn.tk
rx}z|j     
|¡W5d}~XYnXdSr) rrrÚ executemanyrrrrr#r r$)rr%Zseq_of_parametersr"r'rrrr(ssz'AsyncAdapt_aiosqlite_cursor.executemanycGsdSrr)rZ
inputsizesrrrÚ setinputsizes~sz)AsyncAdapt_aiosqlite_cursor.setinputsizesccs|jr|j d¡VqdS©Nr©rÚpoprrrrÚ__iter__sz$AsyncAdapt_aiosqlite_cursor.__iter__cCs|jr|j d¡SdSdSr*r+rrrrÚfetchone…s z$AsyncAdapt_aiosqlite_cursor.fetchonecCs8|dkr|j}|jd|…}|j|d…|jdd…<|Sr*)rr)rÚsizeÚretvalrrrÚ    fetchmany‹s
z%AsyncAdapt_aiosqlite_cursor.fetchmanycCs |jdd…}g|jdd…<|Srr)rr0rrrr!“sz$AsyncAdapt_aiosqlite_cursor.fetchall)N)N)Ú__name__Ú
__module__Ú __qualname__Ú    __slots__r rrrr(r)r-r.r1r!rrrrr >s     
 
r csFeZdZdZdZ‡fdd„Zdd„Zdd„Zdd
d „Zd d „Z    ‡Z
S)ÚAsyncAdapt_aiosqlite_ss_cursorr"Tcstƒj||Žd|_dSr)Úsuperrr")rÚargÚkw©Ú    __class__rrržsz'AsyncAdapt_aiosqlite_ss_cursor.__init__cCs$|jdk    r | |j ¡¡d|_dSr)r"rrrrrrr¢s
z$AsyncAdapt_aiosqlite_ss_cursor.closecCs| |j ¡¡Sr)rr"r.rrrrr.§sz'AsyncAdapt_aiosqlite_ss_cursor.fetchoneNcCs"|dkr|j}| |jj|d¡S)N)r/)rrr"r1)rr/rrrr1ªsz(AsyncAdapt_aiosqlite_ss_cursor.fetchmanycCs| |j ¡¡Sr)rr"r!rrrrr!¯sz'AsyncAdapt_aiosqlite_ss_cursor.fetchall)N) r2r3r4r5r rrr.r1r!Ú __classcell__rrr:rr6™s 
r6c@steZdZeeƒZdZdd„Zedd„ƒZ    e    j
dd„ƒZ    dd„Z dd
d „Z d d „Z dd„Zdd„Zdd„Zdd„ZdS)ÚAsyncAdapt_aiosqlite_connection)ÚdbapicCs||_||_dSr)r>r)rr>Ú
connectionrrrr·sz(AsyncAdapt_aiosqlite_connection.__init__cCs|jjSr)rÚisolation_levelrrrrr@»sz/AsyncAdapt_aiosqlite_connection.isolation_levelc
Cstdd„}t||jj|ƒ}t ¡ ¡}|jj ||f¡z | |¡WSt    k
rn}z| 
|¡W5d}~XYnXdS)NcSs
||_dSr)r@)r?ÚvaluerrrÚset_isoÇsz@AsyncAdapt_aiosqlite_connection.isolation_level.<locals>.set_iso) rrZ_connÚasyncioZget_event_loopZ create_futureZ_txÚ
put_nowaitrr#r$)rrArBÚfunctionÚfuturer'rrrr@¿s  c
OsJz| |jj||Ž¡Wn,tk
rD}z| |¡W5d}~XYnXdSr)rrÚcreate_functionr#r$)rÚargsr9r'rrrrGÔsz/AsyncAdapt_aiosqlite_connection.create_functionFcCs|r t|ƒSt|ƒSdSr)r6r )rr rrrrÚsz&AsyncAdapt_aiosqlite_connection.cursorcOs| |jj||Ž¡Sr)rrr)rrHr9rrrràsz'AsyncAdapt_aiosqlite_connection.executec
CsFz| |j ¡¡Wn,tk
r@}z| |¡W5d}~XYnXdSr)rrÚrollbackr#r$©rr'rrrrIãsz(AsyncAdapt_aiosqlite_connection.rollbackc
CsFz| |j ¡¡Wn,tk
r@}z| |¡W5d}~XYnXdSr)rrÚcommitr#r$rJrrrrKész&AsyncAdapt_aiosqlite_connection.commitc
CsXz| |j ¡¡Wn>tk
r(Yn,tk
rR}z| |¡W5d}~XYnXdSr)rrrÚ
ValueErrorr#r$rJrrrrïs     z%AsyncAdapt_aiosqlite_connection.closecCs2t|tƒr*|jddkr*|jj d¡|‚n|‚dS)Nrúno active connection)Ú
isinstancerLrHr>ÚsqliteÚOperationalErrorrJrrrr$ÿsÿ þÿþz1AsyncAdapt_aiosqlite_connection._handle_exceptionN)F)r2r3r4Ú staticmethodr rr5rÚpropertyr@ÚsetterrGrrrIrKrr$rrrrr=³s
 
 
r=c@seZdZdZeeƒZdS)Ú'AsyncAdaptFallback_aiosqlite_connectionrN)r2r3r4r5rQr
rrrrrrT srTc@s$eZdZdd„Zdd„Zdd„ZdS)ÚAsyncAdapt_aiosqlite_dbapicCs||_||_d|_| ¡dS)NZqmark)Ú    aiosqliterOZ
paramstyleÚ_init_dbapi_attributes)rrVrOrrrrsz#AsyncAdapt_aiosqlite_dbapi.__init__cCs^dD]}t||t|j|ƒƒqdD]}t||t|j|ƒƒq"dD]}t||t|j|ƒƒq@dS)N)Z DatabaseErrorÚErrorZIntegrityErrorZNotSupportedErrorrPZProgrammingErrorZsqlite_versionZsqlite_version_info)ZPARSE_COLNAMESZPARSE_DECLTYPES)ÚBinary)ÚsetattrÚgetattrrVrO)rÚnamerrrrWs 
z1AsyncAdapt_aiosqlite_dbapi._init_dbapi_attributescOsJ| dd¡}|jj||Ž}d|_t |¡r8t|t|ƒƒSt|t    |ƒƒSdS)NÚasync_fallbackFT)
r,rVÚconnectÚdaemonrZasboolrTr
r=r )rr8r9r]r?rrrr^+s 
þþz"AsyncAdapt_aiosqlite_dbapi.connectN)r2r3r4rrWr^rrrrrUsrUc@seZdZdd„ZdS)Ú SQLiteExecutionContext_aiosqlitecCs|jjddS)NT)r )Z_dbapi_connectionrrrrrÚcreate_server_side_cursor@sz:SQLiteExecutionContext_aiosqlite.create_server_side_cursorN)r2r3r4rarrrrr`?sr`csPeZdZdZdZdZdZeZe    dd„ƒZ
e    dd„ƒZ ‡fdd„Z d    d
„Z ‡ZS) ÚSQLiteDialect_aiosqliterVTcCsttdƒtdƒƒS)NrVZsqlite3)rUÚ
__import__)ÚclsrrrÚ import_dbapiNsÿz$SQLiteDialect_aiosqlite.import_dbapicCs| |¡rtjStjSdSr)Z_is_url_file_dbrZNullPoolZ
StaticPool)rdÚurlrrrÚget_pool_classTs
z&SQLiteDialect_aiosqlite.get_pool_classcs.t||jjƒrdt|ƒkrdStƒ |||¡S)NrMT)rNr>rPÚstrr7Ú is_disconnect)rÚer?rr:rrri[sÿ
þz%SQLiteDialect_aiosqlite.is_disconnectcCs|jSr)r)rr?rrrÚget_driver_connectioncsz-SQLiteDialect_aiosqlite.get_driver_connection)r2r3r4ZdriverZsupports_statement_cacheZis_asyncZsupports_server_side_cursorsr`Zexecution_ctx_clsÚ classmethodrergrirkr<rrr:rrbDs
 
 rb)Ú__doc__rCÚ    functoolsrÚbaserZpysqliterÚrrZenginer    Zutil.concurrencyr
r r r6r=rTrUr`rbÚdialectrrrrÚ<module>
s"(        [X.#