4
4
5
5
import sqlite3
6
6
from collections .abc import Callable , Sequence
7
- from functools import partial , wraps
7
+ from functools import partial , update_wrapper
8
8
from logging import Logger , getLogger
9
9
from types import TracebackType
10
10
from typing import Any
@@ -46,18 +46,21 @@ async def __aexit__(
46
46
exception_handled = self ._exception_handler (exc_type , exc_val , exc_tb , self ._log )
47
47
return exception_handled
48
48
49
- @wraps (sqlite3 .Connection .close )
50
49
async def close (self ):
51
50
return await to_thread .run_sync (self ._real_connection .close , limiter = self ._limiter )
52
51
53
- @wraps (sqlite3 .Connection .commit )
52
+ update_wrapper (close , sqlite3 .Connection .close )
53
+
54
54
async def commit (self ):
55
55
return await to_thread .run_sync (self ._real_connection .commit , limiter = self ._limiter )
56
56
57
- @wraps (sqlite3 .Connection .rollback )
57
+ update_wrapper (commit , sqlite3 .Connection .commit )
58
+
58
59
async def rollback (self ):
59
60
return await to_thread .run_sync (self ._real_connection .rollback , limiter = self ._limiter )
60
61
62
+ update_wrapper (rollback , sqlite3 .Connection .rollback )
63
+
61
64
async def cursor (self , factory : Callable [[sqlite3 .Connection ], sqlite3 .Cursor ] = sqlite3 .Cursor ) -> Cursor :
62
65
real_cursor = await to_thread .run_sync (self ._real_connection .cursor , factory , limiter = self ._limiter )
63
66
return Cursor (real_cursor , self ._limiter )
@@ -80,37 +83,44 @@ def rowcount(self) -> int:
80
83
def arraysize (self ) -> int :
81
84
return self ._real_cursor .arraysize
82
85
83
- @wraps (sqlite3 .Cursor .close )
84
86
async def close (self ) -> None :
85
87
await to_thread .run_sync (self ._real_cursor .close , limiter = self ._limiter )
86
88
87
- @wraps (sqlite3 .Cursor .execute )
89
+ update_wrapper (close , sqlite3 .Cursor .close )
90
+
88
91
async def execute (self , sql : str , parameters : Sequence [Any ] = (), / ) -> Cursor :
89
92
real_cursor = await to_thread .run_sync (self ._real_cursor .execute , sql , parameters , limiter = self ._limiter )
90
93
return Cursor (real_cursor , self ._limiter )
91
94
92
- @wraps (sqlite3 .Cursor .executemany )
95
+ update_wrapper (execute , sqlite3 .Cursor .execute )
96
+
93
97
async def executemany (self , sql : str , parameters : Sequence [Any ], / ) -> Cursor :
94
98
real_cursor = await to_thread .run_sync (self ._real_cursor .executemany , sql , parameters , limiter = self ._limiter )
95
99
return Cursor (real_cursor , self ._limiter )
96
100
97
- @wraps (sqlite3 .Cursor .executescript )
101
+ update_wrapper (executemany , sqlite3 .Cursor .executemany )
102
+
98
103
async def executescript (self , sql_script : str , / ) -> Cursor :
99
104
real_cursor = await to_thread .run_sync (self ._real_cursor .executescript , sql_script , limiter = self ._limiter )
100
105
return Cursor (real_cursor , self ._limiter )
101
106
102
- @wraps (sqlite3 .Cursor .fetchone )
107
+ update_wrapper (executescript , sqlite3 .Cursor .executescript )
108
+
103
109
async def fetchone (self ) -> tuple [Any , ...] | None :
104
110
return await to_thread .run_sync (self ._real_cursor .fetchone , limiter = self ._limiter )
105
111
106
- @wraps (sqlite3 .Cursor .fetchmany )
112
+ update_wrapper (fetchone , sqlite3 .Cursor .fetchone )
113
+
107
114
async def fetchmany (self , size : int ) -> list [tuple [Any , ...]]:
108
115
return await to_thread .run_sync (self ._real_cursor .fetchmany , size , limiter = self ._limiter )
109
116
110
- @wraps (sqlite3 .Cursor .fetchall )
117
+ update_wrapper (fetchmany , sqlite3 .Cursor .fetchmany )
118
+
111
119
async def fetchall (self ) -> list [tuple [Any , ...]]:
112
120
return await to_thread .run_sync (self ._real_cursor .fetchall , limiter = self ._limiter )
113
121
122
+ update_wrapper (fetchall , sqlite3 .Cursor .fetchall )
123
+
114
124
115
125
async def connect (
116
126
database : str ,
0 commit comments