sqlspec 0.9.0__py3-none-any.whl → 0.10.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sqlspec might be problematic. Click here for more details.
- sqlspec/__init__.py +2 -1
- sqlspec/adapters/adbc/__init__.py +2 -1
- sqlspec/adapters/adbc/config.py +7 -13
- sqlspec/adapters/adbc/driver.py +160 -21
- sqlspec/adapters/aiosqlite/__init__.py +2 -1
- sqlspec/adapters/aiosqlite/config.py +10 -12
- sqlspec/adapters/aiosqlite/driver.py +160 -22
- sqlspec/adapters/asyncmy/__init__.py +2 -1
- sqlspec/adapters/asyncmy/driver.py +158 -22
- sqlspec/adapters/asyncpg/config.py +1 -3
- sqlspec/adapters/asyncpg/driver.py +143 -5
- sqlspec/adapters/bigquery/__init__.py +4 -0
- sqlspec/adapters/bigquery/config/__init__.py +3 -0
- sqlspec/adapters/bigquery/config/_common.py +40 -0
- sqlspec/adapters/bigquery/config/_sync.py +87 -0
- sqlspec/adapters/bigquery/driver.py +701 -0
- sqlspec/adapters/duckdb/__init__.py +2 -1
- sqlspec/adapters/duckdb/config.py +17 -18
- sqlspec/adapters/duckdb/driver.py +165 -27
- sqlspec/adapters/oracledb/__init__.py +8 -1
- sqlspec/adapters/oracledb/config/_asyncio.py +7 -8
- sqlspec/adapters/oracledb/config/_sync.py +6 -7
- sqlspec/adapters/oracledb/driver.py +311 -42
- sqlspec/adapters/psqlpy/__init__.py +9 -0
- sqlspec/adapters/psqlpy/config.py +11 -19
- sqlspec/adapters/psqlpy/driver.py +171 -19
- sqlspec/adapters/psycopg/__init__.py +8 -1
- sqlspec/adapters/psycopg/config/__init__.py +10 -0
- sqlspec/adapters/psycopg/config/_async.py +6 -7
- sqlspec/adapters/psycopg/config/_sync.py +7 -8
- sqlspec/adapters/psycopg/driver.py +344 -86
- sqlspec/adapters/sqlite/__init__.py +2 -1
- sqlspec/adapters/sqlite/config.py +12 -11
- sqlspec/adapters/sqlite/driver.py +160 -51
- sqlspec/base.py +402 -63
- sqlspec/exceptions.py +9 -0
- sqlspec/extensions/litestar/config.py +3 -11
- sqlspec/extensions/litestar/handlers.py +2 -1
- sqlspec/extensions/litestar/plugin.py +6 -2
- sqlspec/mixins.py +156 -0
- sqlspec/typing.py +19 -1
- {sqlspec-0.9.0.dist-info → sqlspec-0.10.0.dist-info}/METADATA +147 -3
- sqlspec-0.10.0.dist-info/RECORD +67 -0
- sqlspec-0.9.0.dist-info/RECORD +0 -61
- {sqlspec-0.9.0.dist-info → sqlspec-0.10.0.dist-info}/WHEEL +0 -0
- {sqlspec-0.9.0.dist-info → sqlspec-0.10.0.dist-info}/licenses/LICENSE +0 -0
- {sqlspec-0.9.0.dist-info → sqlspec-0.10.0.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,49 +1,77 @@
|
|
|
1
1
|
from contextlib import asynccontextmanager
|
|
2
|
-
from typing import TYPE_CHECKING, Any, Optional, Union, cast
|
|
2
|
+
from typing import TYPE_CHECKING, Any, Optional, Union, cast, overload
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import aiosqlite
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
from sqlspec.base import AsyncDriverAdapterProtocol
|
|
7
|
+
from sqlspec.mixins import SQLTranslatorMixin
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from collections.abc import AsyncGenerator, Sequence
|
|
10
11
|
|
|
11
|
-
from sqlspec.typing import ModelDTOT, StatementParameterType
|
|
12
|
+
from sqlspec.typing import ModelDTOT, StatementParameterType, T
|
|
12
13
|
|
|
13
|
-
__all__ = ("AiosqliteDriver"
|
|
14
|
+
__all__ = ("AiosqliteConnection", "AiosqliteDriver")
|
|
15
|
+
AiosqliteConnection = aiosqlite.Connection
|
|
14
16
|
|
|
15
17
|
|
|
16
|
-
class AiosqliteDriver(
|
|
18
|
+
class AiosqliteDriver(
|
|
19
|
+
SQLTranslatorMixin["AiosqliteConnection"],
|
|
20
|
+
AsyncDriverAdapterProtocol["AiosqliteConnection"],
|
|
21
|
+
):
|
|
17
22
|
"""SQLite Async Driver Adapter."""
|
|
18
23
|
|
|
19
|
-
connection: "
|
|
24
|
+
connection: "AiosqliteConnection"
|
|
20
25
|
dialect: str = "sqlite"
|
|
21
26
|
|
|
22
|
-
def __init__(self, connection: "
|
|
27
|
+
def __init__(self, connection: "AiosqliteConnection") -> None:
|
|
23
28
|
self.connection = connection
|
|
24
29
|
|
|
25
30
|
@staticmethod
|
|
26
|
-
async def _cursor(connection: "
|
|
31
|
+
async def _cursor(connection: "AiosqliteConnection", *args: Any, **kwargs: Any) -> "aiosqlite.Cursor":
|
|
27
32
|
return await connection.cursor(*args, **kwargs)
|
|
28
33
|
|
|
29
34
|
@asynccontextmanager
|
|
30
|
-
async def _with_cursor(self, connection: "
|
|
35
|
+
async def _with_cursor(self, connection: "AiosqliteConnection") -> "AsyncGenerator[aiosqlite.Cursor, None]":
|
|
31
36
|
cursor = await self._cursor(connection)
|
|
32
37
|
try:
|
|
33
38
|
yield cursor
|
|
34
39
|
finally:
|
|
35
40
|
await cursor.close()
|
|
36
41
|
|
|
42
|
+
# --- Public API Methods --- #
|
|
43
|
+
@overload
|
|
44
|
+
async def select(
|
|
45
|
+
self,
|
|
46
|
+
sql: str,
|
|
47
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
48
|
+
/,
|
|
49
|
+
*,
|
|
50
|
+
connection: "Optional[AiosqliteConnection]" = None,
|
|
51
|
+
schema_type: None = None,
|
|
52
|
+
**kwargs: Any,
|
|
53
|
+
) -> "Sequence[dict[str, Any]]": ...
|
|
54
|
+
@overload
|
|
55
|
+
async def select(
|
|
56
|
+
self,
|
|
57
|
+
sql: str,
|
|
58
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
59
|
+
/,
|
|
60
|
+
*,
|
|
61
|
+
connection: "Optional[AiosqliteConnection]" = None,
|
|
62
|
+
schema_type: "type[ModelDTOT]",
|
|
63
|
+
**kwargs: Any,
|
|
64
|
+
) -> "Sequence[ModelDTOT]": ...
|
|
37
65
|
async def select(
|
|
38
66
|
self,
|
|
39
67
|
sql: str,
|
|
40
68
|
parameters: Optional["StatementParameterType"] = None,
|
|
41
69
|
/,
|
|
42
70
|
*,
|
|
43
|
-
connection: Optional["
|
|
71
|
+
connection: Optional["AiosqliteConnection"] = None,
|
|
44
72
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
45
73
|
**kwargs: Any,
|
|
46
|
-
) -> "
|
|
74
|
+
) -> "Sequence[Union[ModelDTOT, dict[str, Any]]]":
|
|
47
75
|
"""Fetch data from the database.
|
|
48
76
|
|
|
49
77
|
Returns:
|
|
@@ -61,13 +89,35 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
61
89
|
return [dict(zip(column_names, row)) for row in results] # pyright: ignore[reportUnknownArgumentType]
|
|
62
90
|
return [cast("ModelDTOT", schema_type(**dict(zip(column_names, row)))) for row in results] # pyright: ignore[reportUnknownArgumentType]
|
|
63
91
|
|
|
92
|
+
@overload
|
|
93
|
+
async def select_one(
|
|
94
|
+
self,
|
|
95
|
+
sql: str,
|
|
96
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
97
|
+
/,
|
|
98
|
+
*,
|
|
99
|
+
connection: "Optional[AiosqliteConnection]" = None,
|
|
100
|
+
schema_type: None = None,
|
|
101
|
+
**kwargs: Any,
|
|
102
|
+
) -> "dict[str, Any]": ...
|
|
103
|
+
@overload
|
|
104
|
+
async def select_one(
|
|
105
|
+
self,
|
|
106
|
+
sql: str,
|
|
107
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
108
|
+
/,
|
|
109
|
+
*,
|
|
110
|
+
connection: "Optional[AiosqliteConnection]" = None,
|
|
111
|
+
schema_type: "type[ModelDTOT]",
|
|
112
|
+
**kwargs: Any,
|
|
113
|
+
) -> "ModelDTOT": ...
|
|
64
114
|
async def select_one(
|
|
65
115
|
self,
|
|
66
116
|
sql: str,
|
|
67
117
|
parameters: Optional["StatementParameterType"] = None,
|
|
68
118
|
/,
|
|
69
119
|
*,
|
|
70
|
-
connection: Optional["
|
|
120
|
+
connection: Optional["AiosqliteConnection"] = None,
|
|
71
121
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
72
122
|
**kwargs: Any,
|
|
73
123
|
) -> "Union[ModelDTOT, dict[str, Any]]":
|
|
@@ -87,13 +137,35 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
87
137
|
return dict(zip(column_names, result)) # pyright: ignore[reportUnknownArgumentType, reportUnknownVariableType]
|
|
88
138
|
return cast("ModelDTOT", schema_type(**dict(zip(column_names, result)))) # pyright: ignore[reportUnknownArgumentType]
|
|
89
139
|
|
|
140
|
+
@overload
|
|
141
|
+
async def select_one_or_none(
|
|
142
|
+
self,
|
|
143
|
+
sql: str,
|
|
144
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
145
|
+
/,
|
|
146
|
+
*,
|
|
147
|
+
connection: "Optional[AiosqliteConnection]" = None,
|
|
148
|
+
schema_type: None = None,
|
|
149
|
+
**kwargs: Any,
|
|
150
|
+
) -> "Optional[dict[str, Any]]": ...
|
|
151
|
+
@overload
|
|
152
|
+
async def select_one_or_none(
|
|
153
|
+
self,
|
|
154
|
+
sql: str,
|
|
155
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
156
|
+
/,
|
|
157
|
+
*,
|
|
158
|
+
connection: "Optional[AiosqliteConnection]" = None,
|
|
159
|
+
schema_type: "type[ModelDTOT]",
|
|
160
|
+
**kwargs: Any,
|
|
161
|
+
) -> "Optional[ModelDTOT]": ...
|
|
90
162
|
async def select_one_or_none(
|
|
91
163
|
self,
|
|
92
164
|
sql: str,
|
|
93
165
|
parameters: Optional["StatementParameterType"] = None,
|
|
94
166
|
/,
|
|
95
167
|
*,
|
|
96
|
-
connection: Optional["
|
|
168
|
+
connection: Optional["AiosqliteConnection"] = None,
|
|
97
169
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
98
170
|
**kwargs: Any,
|
|
99
171
|
) -> "Optional[Union[ModelDTOT, dict[str, Any]]]":
|
|
@@ -114,13 +186,35 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
114
186
|
return dict(zip(column_names, result)) # pyright: ignore[reportUnknownArgumentType, reportUnknownVariableType]
|
|
115
187
|
return cast("ModelDTOT", schema_type(**dict(zip(column_names, result)))) # pyright: ignore[reportUnknownArgumentType]
|
|
116
188
|
|
|
189
|
+
@overload
|
|
190
|
+
async def select_value(
|
|
191
|
+
self,
|
|
192
|
+
sql: str,
|
|
193
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
194
|
+
/,
|
|
195
|
+
*,
|
|
196
|
+
connection: "Optional[AiosqliteConnection]" = None,
|
|
197
|
+
schema_type: None = None,
|
|
198
|
+
**kwargs: Any,
|
|
199
|
+
) -> "Any": ...
|
|
200
|
+
@overload
|
|
201
|
+
async def select_value(
|
|
202
|
+
self,
|
|
203
|
+
sql: str,
|
|
204
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
205
|
+
/,
|
|
206
|
+
*,
|
|
207
|
+
connection: "Optional[AiosqliteConnection]" = None,
|
|
208
|
+
schema_type: "type[T]",
|
|
209
|
+
**kwargs: Any,
|
|
210
|
+
) -> "T": ...
|
|
117
211
|
async def select_value(
|
|
118
212
|
self,
|
|
119
213
|
sql: str,
|
|
120
214
|
parameters: "Optional[StatementParameterType]" = None,
|
|
121
215
|
/,
|
|
122
216
|
*,
|
|
123
|
-
connection: "Optional[
|
|
217
|
+
connection: "Optional[AiosqliteConnection]" = None,
|
|
124
218
|
schema_type: "Optional[type[T]]" = None,
|
|
125
219
|
**kwargs: Any,
|
|
126
220
|
) -> "Union[T, Any]":
|
|
@@ -139,13 +233,35 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
139
233
|
return result[0]
|
|
140
234
|
return schema_type(result[0]) # type: ignore[call-arg]
|
|
141
235
|
|
|
236
|
+
@overload
|
|
237
|
+
async def select_value_or_none(
|
|
238
|
+
self,
|
|
239
|
+
sql: str,
|
|
240
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
241
|
+
/,
|
|
242
|
+
*,
|
|
243
|
+
connection: "Optional[AiosqliteConnection]" = None,
|
|
244
|
+
schema_type: None = None,
|
|
245
|
+
**kwargs: Any,
|
|
246
|
+
) -> "Optional[Any]": ...
|
|
247
|
+
@overload
|
|
142
248
|
async def select_value_or_none(
|
|
143
249
|
self,
|
|
144
250
|
sql: str,
|
|
145
251
|
parameters: "Optional[StatementParameterType]" = None,
|
|
146
252
|
/,
|
|
147
253
|
*,
|
|
148
|
-
connection: "Optional[
|
|
254
|
+
connection: "Optional[AiosqliteConnection]" = None,
|
|
255
|
+
schema_type: "type[T]",
|
|
256
|
+
**kwargs: Any,
|
|
257
|
+
) -> "Optional[T]": ...
|
|
258
|
+
async def select_value_or_none(
|
|
259
|
+
self,
|
|
260
|
+
sql: str,
|
|
261
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
262
|
+
/,
|
|
263
|
+
*,
|
|
264
|
+
connection: "Optional[AiosqliteConnection]" = None,
|
|
149
265
|
schema_type: "Optional[type[T]]" = None,
|
|
150
266
|
**kwargs: Any,
|
|
151
267
|
) -> "Optional[Union[T, Any]]":
|
|
@@ -171,7 +287,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
171
287
|
parameters: Optional["StatementParameterType"] = None,
|
|
172
288
|
/,
|
|
173
289
|
*,
|
|
174
|
-
connection: Optional["
|
|
290
|
+
connection: Optional["AiosqliteConnection"] = None,
|
|
175
291
|
**kwargs: Any,
|
|
176
292
|
) -> int:
|
|
177
293
|
"""Insert, update, or delete data from the database.
|
|
@@ -186,13 +302,35 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
186
302
|
await cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
187
303
|
return cursor.rowcount if hasattr(cursor, "rowcount") else -1 # pyright: ignore[reportUnknownVariableType, reportGeneralTypeIssues]
|
|
188
304
|
|
|
305
|
+
@overload
|
|
306
|
+
async def insert_update_delete_returning(
|
|
307
|
+
self,
|
|
308
|
+
sql: str,
|
|
309
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
310
|
+
/,
|
|
311
|
+
*,
|
|
312
|
+
connection: "Optional[AiosqliteConnection]" = None,
|
|
313
|
+
schema_type: None = None,
|
|
314
|
+
**kwargs: Any,
|
|
315
|
+
) -> "dict[str, Any]": ...
|
|
316
|
+
@overload
|
|
317
|
+
async def insert_update_delete_returning(
|
|
318
|
+
self,
|
|
319
|
+
sql: str,
|
|
320
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
321
|
+
/,
|
|
322
|
+
*,
|
|
323
|
+
connection: "Optional[AiosqliteConnection]" = None,
|
|
324
|
+
schema_type: "type[ModelDTOT]",
|
|
325
|
+
**kwargs: Any,
|
|
326
|
+
) -> "ModelDTOT": ...
|
|
189
327
|
async def insert_update_delete_returning(
|
|
190
328
|
self,
|
|
191
329
|
sql: str,
|
|
192
330
|
parameters: Optional["StatementParameterType"] = None,
|
|
193
331
|
/,
|
|
194
332
|
*,
|
|
195
|
-
connection: Optional["
|
|
333
|
+
connection: Optional["AiosqliteConnection"] = None,
|
|
196
334
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
197
335
|
**kwargs: Any,
|
|
198
336
|
) -> "Optional[Union[dict[str, Any], ModelDTOT]]":
|
|
@@ -220,7 +358,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
220
358
|
parameters: Optional["StatementParameterType"] = None,
|
|
221
359
|
/,
|
|
222
360
|
*,
|
|
223
|
-
connection: Optional["
|
|
361
|
+
connection: Optional["AiosqliteConnection"] = None,
|
|
224
362
|
**kwargs: Any,
|
|
225
363
|
) -> str:
|
|
226
364
|
"""Execute a script.
|
|
@@ -241,7 +379,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
241
379
|
parameters: Optional["StatementParameterType"] = None,
|
|
242
380
|
/,
|
|
243
381
|
*,
|
|
244
|
-
connection: Optional["
|
|
382
|
+
connection: Optional["AiosqliteConnection"] = None,
|
|
245
383
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
246
384
|
**kwargs: Any,
|
|
247
385
|
) -> "Optional[Union[dict[str, Any], ModelDTOT]]":
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
from sqlspec.adapters.asyncmy.config import AsyncmyConfig, AsyncmyPoolConfig
|
|
2
|
-
from sqlspec.adapters.asyncmy.driver import AsyncmyDriver # type: ignore[attr-defined]
|
|
2
|
+
from sqlspec.adapters.asyncmy.driver import AsyncmyConnection, AsyncmyDriver # type: ignore[attr-defined]
|
|
3
3
|
|
|
4
4
|
__all__ = (
|
|
5
5
|
"AsyncmyConfig",
|
|
6
|
+
"AsyncmyConnection",
|
|
6
7
|
"AsyncmyDriver",
|
|
7
8
|
"AsyncmyPoolConfig",
|
|
8
9
|
)
|
|
@@ -1,51 +1,77 @@
|
|
|
1
1
|
# type: ignore
|
|
2
|
-
from collections.abc import AsyncGenerator
|
|
2
|
+
from collections.abc import AsyncGenerator, Sequence
|
|
3
3
|
from contextlib import asynccontextmanager
|
|
4
|
-
from typing import TYPE_CHECKING, Any, Optional, Union, cast
|
|
4
|
+
from typing import TYPE_CHECKING, Any, Optional, Union, cast, overload
|
|
5
5
|
|
|
6
|
-
from
|
|
6
|
+
from asyncmy import Connection
|
|
7
|
+
|
|
8
|
+
from sqlspec.base import AsyncDriverAdapterProtocol
|
|
9
|
+
from sqlspec.mixins import SQLTranslatorMixin
|
|
7
10
|
|
|
8
11
|
if TYPE_CHECKING:
|
|
9
|
-
from asyncmy import Connection
|
|
10
12
|
from asyncmy.cursors import Cursor
|
|
11
13
|
|
|
12
|
-
from sqlspec.typing import ModelDTOT, StatementParameterType
|
|
14
|
+
from sqlspec.typing import ModelDTOT, StatementParameterType, T
|
|
13
15
|
|
|
14
16
|
__all__ = ("AsyncmyDriver",)
|
|
15
17
|
|
|
18
|
+
AsyncmyConnection = Connection
|
|
19
|
+
|
|
16
20
|
|
|
17
|
-
class AsyncmyDriver(
|
|
21
|
+
class AsyncmyDriver(
|
|
22
|
+
SQLTranslatorMixin["AsyncmyConnection"],
|
|
23
|
+
AsyncDriverAdapterProtocol["AsyncmyConnection"],
|
|
24
|
+
):
|
|
18
25
|
"""Asyncmy MySQL/MariaDB Driver Adapter."""
|
|
19
26
|
|
|
20
|
-
connection: "
|
|
27
|
+
connection: "AsyncmyConnection"
|
|
21
28
|
dialect: str = "mysql"
|
|
22
29
|
|
|
23
|
-
def __init__(self, connection: "
|
|
30
|
+
def __init__(self, connection: "AsyncmyConnection") -> None:
|
|
24
31
|
self.connection = connection
|
|
25
32
|
|
|
26
|
-
@staticmethod
|
|
27
|
-
async def _cursor(connection: "Connection") -> "Cursor":
|
|
28
|
-
return await connection.cursor()
|
|
29
|
-
|
|
30
33
|
@staticmethod
|
|
31
34
|
@asynccontextmanager
|
|
32
|
-
async def _with_cursor(connection: "
|
|
35
|
+
async def _with_cursor(connection: "AsyncmyConnection") -> AsyncGenerator["Cursor", None]:
|
|
33
36
|
cursor = connection.cursor()
|
|
34
37
|
try:
|
|
35
38
|
yield cursor
|
|
36
39
|
finally:
|
|
37
40
|
await cursor.close()
|
|
38
41
|
|
|
42
|
+
# --- Public API Methods --- #
|
|
43
|
+
@overload
|
|
44
|
+
async def select(
|
|
45
|
+
self,
|
|
46
|
+
sql: str,
|
|
47
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
48
|
+
/,
|
|
49
|
+
*,
|
|
50
|
+
connection: "Optional[AsyncmyConnection]" = None,
|
|
51
|
+
schema_type: None = None,
|
|
52
|
+
**kwargs: Any,
|
|
53
|
+
) -> "Sequence[dict[str, Any]]": ...
|
|
54
|
+
@overload
|
|
55
|
+
async def select(
|
|
56
|
+
self,
|
|
57
|
+
sql: str,
|
|
58
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
59
|
+
/,
|
|
60
|
+
*,
|
|
61
|
+
connection: "Optional[AsyncmyConnection]" = None,
|
|
62
|
+
schema_type: "type[ModelDTOT]",
|
|
63
|
+
**kwargs: Any,
|
|
64
|
+
) -> "Sequence[ModelDTOT]": ...
|
|
39
65
|
async def select(
|
|
40
66
|
self,
|
|
41
67
|
sql: str,
|
|
42
68
|
parameters: Optional["StatementParameterType"] = None,
|
|
43
69
|
/,
|
|
44
70
|
*,
|
|
45
|
-
connection: Optional["
|
|
71
|
+
connection: Optional["AsyncmyConnection"] = None,
|
|
46
72
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
47
73
|
**kwargs: Any,
|
|
48
|
-
) -> "
|
|
74
|
+
) -> "Sequence[Union[ModelDTOT, dict[str, Any]]]":
|
|
49
75
|
"""Fetch data from the database.
|
|
50
76
|
|
|
51
77
|
Returns:
|
|
@@ -63,13 +89,35 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
63
89
|
return [dict(zip(column_names, row)) for row in results]
|
|
64
90
|
return [schema_type(**dict(zip(column_names, row))) for row in results]
|
|
65
91
|
|
|
92
|
+
@overload
|
|
93
|
+
async def select_one(
|
|
94
|
+
self,
|
|
95
|
+
sql: str,
|
|
96
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
97
|
+
/,
|
|
98
|
+
*,
|
|
99
|
+
connection: "Optional[AsyncmyConnection]" = None,
|
|
100
|
+
schema_type: None = None,
|
|
101
|
+
**kwargs: Any,
|
|
102
|
+
) -> "dict[str, Any]": ...
|
|
103
|
+
@overload
|
|
104
|
+
async def select_one(
|
|
105
|
+
self,
|
|
106
|
+
sql: str,
|
|
107
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
108
|
+
/,
|
|
109
|
+
*,
|
|
110
|
+
connection: "Optional[AsyncmyConnection]" = None,
|
|
111
|
+
schema_type: "type[ModelDTOT]",
|
|
112
|
+
**kwargs: Any,
|
|
113
|
+
) -> "ModelDTOT": ...
|
|
66
114
|
async def select_one(
|
|
67
115
|
self,
|
|
68
116
|
sql: str,
|
|
69
117
|
parameters: Optional["StatementParameterType"] = None,
|
|
70
118
|
/,
|
|
71
119
|
*,
|
|
72
|
-
connection: Optional["
|
|
120
|
+
connection: Optional["AsyncmyConnection"] = None,
|
|
73
121
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
74
122
|
**kwargs: Any,
|
|
75
123
|
) -> "Union[ModelDTOT, dict[str, Any]]":
|
|
@@ -89,13 +137,35 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
89
137
|
return dict(zip(column_names, result))
|
|
90
138
|
return cast("ModelDTOT", schema_type(**dict(zip(column_names, result))))
|
|
91
139
|
|
|
140
|
+
@overload
|
|
141
|
+
async def select_one_or_none(
|
|
142
|
+
self,
|
|
143
|
+
sql: str,
|
|
144
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
145
|
+
/,
|
|
146
|
+
*,
|
|
147
|
+
connection: "Optional[AsyncmyConnection]" = None,
|
|
148
|
+
schema_type: None = None,
|
|
149
|
+
**kwargs: Any,
|
|
150
|
+
) -> "Optional[dict[str, Any]]": ...
|
|
151
|
+
@overload
|
|
152
|
+
async def select_one_or_none(
|
|
153
|
+
self,
|
|
154
|
+
sql: str,
|
|
155
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
156
|
+
/,
|
|
157
|
+
*,
|
|
158
|
+
connection: "Optional[AsyncmyConnection]" = None,
|
|
159
|
+
schema_type: "type[ModelDTOT]",
|
|
160
|
+
**kwargs: Any,
|
|
161
|
+
) -> "Optional[ModelDTOT]": ...
|
|
92
162
|
async def select_one_or_none(
|
|
93
163
|
self,
|
|
94
164
|
sql: str,
|
|
95
165
|
parameters: Optional["StatementParameterType"] = None,
|
|
96
166
|
/,
|
|
97
167
|
*,
|
|
98
|
-
connection: Optional["
|
|
168
|
+
connection: Optional["AsyncmyConnection"] = None,
|
|
99
169
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
100
170
|
**kwargs: Any,
|
|
101
171
|
) -> "Optional[Union[ModelDTOT, dict[str, Any]]]":
|
|
@@ -116,13 +186,35 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
116
186
|
return dict(zip(column_names, result))
|
|
117
187
|
return cast("ModelDTOT", schema_type(**dict(zip(column_names, result))))
|
|
118
188
|
|
|
189
|
+
@overload
|
|
190
|
+
async def select_value(
|
|
191
|
+
self,
|
|
192
|
+
sql: str,
|
|
193
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
194
|
+
/,
|
|
195
|
+
*,
|
|
196
|
+
connection: "Optional[AsyncmyConnection]" = None,
|
|
197
|
+
schema_type: None = None,
|
|
198
|
+
**kwargs: Any,
|
|
199
|
+
) -> "Any": ...
|
|
200
|
+
@overload
|
|
201
|
+
async def select_value(
|
|
202
|
+
self,
|
|
203
|
+
sql: str,
|
|
204
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
205
|
+
/,
|
|
206
|
+
*,
|
|
207
|
+
connection: "Optional[AsyncmyConnection]" = None,
|
|
208
|
+
schema_type: "type[T]",
|
|
209
|
+
**kwargs: Any,
|
|
210
|
+
) -> "T": ...
|
|
119
211
|
async def select_value(
|
|
120
212
|
self,
|
|
121
213
|
sql: str,
|
|
122
214
|
parameters: "Optional[StatementParameterType]" = None,
|
|
123
215
|
/,
|
|
124
216
|
*,
|
|
125
|
-
connection: "Optional[
|
|
217
|
+
connection: "Optional[AsyncmyConnection]" = None,
|
|
126
218
|
schema_type: "Optional[type[T]]" = None,
|
|
127
219
|
**kwargs: Any,
|
|
128
220
|
) -> "Union[T, Any]":
|
|
@@ -144,13 +236,35 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
144
236
|
return schema_type(value) # type: ignore[call-arg]
|
|
145
237
|
return value
|
|
146
238
|
|
|
239
|
+
@overload
|
|
240
|
+
async def select_value_or_none(
|
|
241
|
+
self,
|
|
242
|
+
sql: str,
|
|
243
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
244
|
+
/,
|
|
245
|
+
*,
|
|
246
|
+
connection: "Optional[AsyncmyConnection]" = None,
|
|
247
|
+
schema_type: None = None,
|
|
248
|
+
**kwargs: Any,
|
|
249
|
+
) -> "Optional[Any]": ...
|
|
250
|
+
@overload
|
|
147
251
|
async def select_value_or_none(
|
|
148
252
|
self,
|
|
149
253
|
sql: str,
|
|
150
254
|
parameters: "Optional[StatementParameterType]" = None,
|
|
151
255
|
/,
|
|
152
256
|
*,
|
|
153
|
-
connection: "Optional[
|
|
257
|
+
connection: "Optional[AsyncmyConnection]" = None,
|
|
258
|
+
schema_type: "type[T]",
|
|
259
|
+
**kwargs: Any,
|
|
260
|
+
) -> "Optional[T]": ...
|
|
261
|
+
async def select_value_or_none(
|
|
262
|
+
self,
|
|
263
|
+
sql: str,
|
|
264
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
265
|
+
/,
|
|
266
|
+
*,
|
|
267
|
+
connection: "Optional[AsyncmyConnection]" = None,
|
|
154
268
|
schema_type: "Optional[type[T]]" = None,
|
|
155
269
|
**kwargs: Any,
|
|
156
270
|
) -> "Optional[Union[T, Any]]":
|
|
@@ -180,7 +294,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
180
294
|
parameters: Optional["StatementParameterType"] = None,
|
|
181
295
|
/,
|
|
182
296
|
*,
|
|
183
|
-
connection: Optional["
|
|
297
|
+
connection: Optional["AsyncmyConnection"] = None,
|
|
184
298
|
**kwargs: Any,
|
|
185
299
|
) -> int:
|
|
186
300
|
"""Insert, update, or delete data from the database.
|
|
@@ -195,13 +309,35 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
195
309
|
await cursor.execute(sql, parameters)
|
|
196
310
|
return cursor.rowcount
|
|
197
311
|
|
|
312
|
+
@overload
|
|
313
|
+
async def insert_update_delete_returning(
|
|
314
|
+
self,
|
|
315
|
+
sql: str,
|
|
316
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
317
|
+
/,
|
|
318
|
+
*,
|
|
319
|
+
connection: "Optional[AsyncmyConnection]" = None,
|
|
320
|
+
schema_type: None = None,
|
|
321
|
+
**kwargs: Any,
|
|
322
|
+
) -> "dict[str, Any]": ...
|
|
323
|
+
@overload
|
|
324
|
+
async def insert_update_delete_returning(
|
|
325
|
+
self,
|
|
326
|
+
sql: str,
|
|
327
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
328
|
+
/,
|
|
329
|
+
*,
|
|
330
|
+
connection: "Optional[AsyncmyConnection]" = None,
|
|
331
|
+
schema_type: "type[ModelDTOT]",
|
|
332
|
+
**kwargs: Any,
|
|
333
|
+
) -> "ModelDTOT": ...
|
|
198
334
|
async def insert_update_delete_returning(
|
|
199
335
|
self,
|
|
200
336
|
sql: str,
|
|
201
337
|
parameters: Optional["StatementParameterType"] = None,
|
|
202
338
|
/,
|
|
203
339
|
*,
|
|
204
|
-
connection: Optional["
|
|
340
|
+
connection: Optional["AsyncmyConnection"] = None,
|
|
205
341
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
206
342
|
**kwargs: Any,
|
|
207
343
|
) -> "Optional[Union[dict[str, Any], ModelDTOT]]":
|
|
@@ -230,7 +366,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
230
366
|
parameters: Optional["StatementParameterType"] = None,
|
|
231
367
|
/,
|
|
232
368
|
*,
|
|
233
|
-
connection: Optional["
|
|
369
|
+
connection: Optional["AsyncmyConnection"] = None,
|
|
234
370
|
**kwargs: Any,
|
|
235
371
|
) -> str:
|
|
236
372
|
"""Execute a script.
|
|
@@ -190,9 +190,7 @@ class AsyncpgConfig(AsyncDatabaseConfig["AsyncpgConnection", "Pool", "AsyncpgDri
|
|
|
190
190
|
raise ImproperConfigurationError(msg) from e
|
|
191
191
|
|
|
192
192
|
@asynccontextmanager
|
|
193
|
-
async def provide_connection(
|
|
194
|
-
self, *args: "Any", **kwargs: "Any"
|
|
195
|
-
) -> "AsyncGenerator[PoolConnectionProxy[Any], None]": # pyright: ignore[reportMissingTypeArgument,reportUnknownParameterType]
|
|
193
|
+
async def provide_connection(self, *args: "Any", **kwargs: "Any") -> "AsyncGenerator[AsyncpgConnection, None]": # pyright: ignore[reportMissingTypeArgument,reportUnknownParameterType]
|
|
196
194
|
"""Create a connection instance.
|
|
197
195
|
|
|
198
196
|
Yields:
|