sqlspec 0.8.0__py3-none-any.whl → 0.9.1__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/_typing.py +39 -6
- sqlspec/adapters/adbc/__init__.py +2 -2
- sqlspec/adapters/adbc/config.py +34 -11
- sqlspec/adapters/adbc/driver.py +302 -111
- sqlspec/adapters/aiosqlite/__init__.py +2 -2
- sqlspec/adapters/aiosqlite/config.py +2 -2
- sqlspec/adapters/aiosqlite/driver.py +164 -42
- sqlspec/adapters/asyncmy/__init__.py +3 -3
- sqlspec/adapters/asyncmy/config.py +11 -12
- sqlspec/adapters/asyncmy/driver.py +161 -37
- sqlspec/adapters/asyncpg/__init__.py +5 -5
- sqlspec/adapters/asyncpg/config.py +17 -19
- sqlspec/adapters/asyncpg/driver.py +386 -96
- sqlspec/adapters/duckdb/__init__.py +2 -2
- sqlspec/adapters/duckdb/config.py +2 -2
- sqlspec/adapters/duckdb/driver.py +190 -60
- sqlspec/adapters/oracledb/__init__.py +8 -8
- sqlspec/adapters/oracledb/config/__init__.py +6 -6
- sqlspec/adapters/oracledb/config/_asyncio.py +9 -10
- sqlspec/adapters/oracledb/config/_sync.py +8 -9
- sqlspec/adapters/oracledb/driver.py +384 -45
- sqlspec/adapters/psqlpy/__init__.py +0 -0
- sqlspec/adapters/psqlpy/config.py +250 -0
- sqlspec/adapters/psqlpy/driver.py +481 -0
- sqlspec/adapters/psycopg/__init__.py +10 -5
- sqlspec/adapters/psycopg/config/__init__.py +6 -6
- sqlspec/adapters/psycopg/config/_async.py +12 -12
- sqlspec/adapters/psycopg/config/_sync.py +13 -13
- sqlspec/adapters/psycopg/driver.py +432 -222
- sqlspec/adapters/sqlite/__init__.py +2 -2
- sqlspec/adapters/sqlite/config.py +2 -2
- sqlspec/adapters/sqlite/driver.py +176 -72
- sqlspec/base.py +687 -161
- sqlspec/exceptions.py +30 -0
- sqlspec/extensions/litestar/config.py +6 -0
- sqlspec/extensions/litestar/handlers.py +25 -0
- sqlspec/extensions/litestar/plugin.py +8 -1
- sqlspec/statement.py +373 -0
- sqlspec/typing.py +10 -1
- {sqlspec-0.8.0.dist-info → sqlspec-0.9.1.dist-info}/METADATA +144 -2
- sqlspec-0.9.1.dist-info/RECORD +61 -0
- sqlspec-0.8.0.dist-info/RECORD +0 -57
- {sqlspec-0.8.0.dist-info → sqlspec-0.9.1.dist-info}/WHEEL +0 -0
- {sqlspec-0.8.0.dist-info → sqlspec-0.9.1.dist-info}/licenses/LICENSE +0 -0
- {sqlspec-0.8.0.dist-info → sqlspec-0.9.1.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
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
|
from sqlspec.base import AsyncDriverAdapterProtocol, T
|
|
5
5
|
|
|
6
6
|
if TYPE_CHECKING:
|
|
7
|
-
from collections.abc import AsyncGenerator
|
|
7
|
+
from collections.abc import AsyncGenerator, Sequence
|
|
8
8
|
|
|
9
9
|
from aiosqlite import Connection, Cursor
|
|
10
10
|
|
|
@@ -17,6 +17,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
17
17
|
"""SQLite Async Driver Adapter."""
|
|
18
18
|
|
|
19
19
|
connection: "Connection"
|
|
20
|
+
dialect: str = "sqlite"
|
|
20
21
|
|
|
21
22
|
def __init__(self, connection: "Connection") -> None:
|
|
22
23
|
self.connection = connection
|
|
@@ -33,50 +34,46 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
33
34
|
finally:
|
|
34
35
|
await cursor.close()
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
# Replace :key with ? in the SQL
|
|
60
|
-
processed_sql = processed_sql.replace(f":{key}", "?")
|
|
61
|
-
processed_params.append(value)
|
|
62
|
-
|
|
63
|
-
return processed_sql, tuple(processed_params)
|
|
64
|
-
|
|
37
|
+
# --- Public API Methods --- #
|
|
38
|
+
@overload
|
|
39
|
+
async def select(
|
|
40
|
+
self,
|
|
41
|
+
sql: str,
|
|
42
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
43
|
+
/,
|
|
44
|
+
*,
|
|
45
|
+
connection: "Optional[Connection]" = None,
|
|
46
|
+
schema_type: None = None,
|
|
47
|
+
**kwargs: Any,
|
|
48
|
+
) -> "Sequence[dict[str, Any]]": ...
|
|
49
|
+
@overload
|
|
50
|
+
async def select(
|
|
51
|
+
self,
|
|
52
|
+
sql: str,
|
|
53
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
54
|
+
/,
|
|
55
|
+
*,
|
|
56
|
+
connection: "Optional[Connection]" = None,
|
|
57
|
+
schema_type: "type[ModelDTOT]",
|
|
58
|
+
**kwargs: Any,
|
|
59
|
+
) -> "Sequence[ModelDTOT]": ...
|
|
65
60
|
async def select(
|
|
66
61
|
self,
|
|
67
62
|
sql: str,
|
|
68
63
|
parameters: Optional["StatementParameterType"] = None,
|
|
69
64
|
/,
|
|
65
|
+
*,
|
|
70
66
|
connection: Optional["Connection"] = None,
|
|
71
67
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
72
|
-
|
|
68
|
+
**kwargs: Any,
|
|
69
|
+
) -> "Sequence[Union[ModelDTOT, dict[str, Any]]]":
|
|
73
70
|
"""Fetch data from the database.
|
|
74
71
|
|
|
75
72
|
Returns:
|
|
76
73
|
List of row data as either model instances or dictionaries.
|
|
77
74
|
"""
|
|
78
75
|
connection = self._connection(connection)
|
|
79
|
-
sql, parameters = self._process_sql_params(sql, parameters)
|
|
76
|
+
sql, parameters = self._process_sql_params(sql, parameters, **kwargs)
|
|
80
77
|
async with self._with_cursor(connection) as cursor:
|
|
81
78
|
await cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
82
79
|
results = await cursor.fetchall() # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
|
|
@@ -87,13 +84,37 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
87
84
|
return [dict(zip(column_names, row)) for row in results] # pyright: ignore[reportUnknownArgumentType]
|
|
88
85
|
return [cast("ModelDTOT", schema_type(**dict(zip(column_names, row)))) for row in results] # pyright: ignore[reportUnknownArgumentType]
|
|
89
86
|
|
|
87
|
+
@overload
|
|
88
|
+
async def select_one(
|
|
89
|
+
self,
|
|
90
|
+
sql: str,
|
|
91
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
92
|
+
/,
|
|
93
|
+
*,
|
|
94
|
+
connection: "Optional[Connection]" = None,
|
|
95
|
+
schema_type: None = None,
|
|
96
|
+
**kwargs: Any,
|
|
97
|
+
) -> "dict[str, Any]": ...
|
|
98
|
+
@overload
|
|
99
|
+
async def select_one(
|
|
100
|
+
self,
|
|
101
|
+
sql: str,
|
|
102
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
103
|
+
/,
|
|
104
|
+
*,
|
|
105
|
+
connection: "Optional[Connection]" = None,
|
|
106
|
+
schema_type: "type[ModelDTOT]",
|
|
107
|
+
**kwargs: Any,
|
|
108
|
+
) -> "ModelDTOT": ...
|
|
90
109
|
async def select_one(
|
|
91
110
|
self,
|
|
92
111
|
sql: str,
|
|
93
112
|
parameters: Optional["StatementParameterType"] = None,
|
|
94
113
|
/,
|
|
114
|
+
*,
|
|
95
115
|
connection: Optional["Connection"] = None,
|
|
96
116
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
117
|
+
**kwargs: Any,
|
|
97
118
|
) -> "Union[ModelDTOT, dict[str, Any]]":
|
|
98
119
|
"""Fetch one row from the database.
|
|
99
120
|
|
|
@@ -101,7 +122,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
101
122
|
The first row of the query results.
|
|
102
123
|
"""
|
|
103
124
|
connection = self._connection(connection)
|
|
104
|
-
sql, parameters = self._process_sql_params(sql, parameters)
|
|
125
|
+
sql, parameters = self._process_sql_params(sql, parameters, **kwargs)
|
|
105
126
|
async with self._with_cursor(connection) as cursor:
|
|
106
127
|
await cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
107
128
|
result = await cursor.fetchone() # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
|
|
@@ -111,13 +132,37 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
111
132
|
return dict(zip(column_names, result)) # pyright: ignore[reportUnknownArgumentType, reportUnknownVariableType]
|
|
112
133
|
return cast("ModelDTOT", schema_type(**dict(zip(column_names, result)))) # pyright: ignore[reportUnknownArgumentType]
|
|
113
134
|
|
|
135
|
+
@overload
|
|
136
|
+
async def select_one_or_none(
|
|
137
|
+
self,
|
|
138
|
+
sql: str,
|
|
139
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
140
|
+
/,
|
|
141
|
+
*,
|
|
142
|
+
connection: "Optional[Connection]" = None,
|
|
143
|
+
schema_type: None = None,
|
|
144
|
+
**kwargs: Any,
|
|
145
|
+
) -> "Optional[dict[str, Any]]": ...
|
|
146
|
+
@overload
|
|
147
|
+
async def select_one_or_none(
|
|
148
|
+
self,
|
|
149
|
+
sql: str,
|
|
150
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
151
|
+
/,
|
|
152
|
+
*,
|
|
153
|
+
connection: "Optional[Connection]" = None,
|
|
154
|
+
schema_type: "type[ModelDTOT]",
|
|
155
|
+
**kwargs: Any,
|
|
156
|
+
) -> "Optional[ModelDTOT]": ...
|
|
114
157
|
async def select_one_or_none(
|
|
115
158
|
self,
|
|
116
159
|
sql: str,
|
|
117
160
|
parameters: Optional["StatementParameterType"] = None,
|
|
118
161
|
/,
|
|
162
|
+
*,
|
|
119
163
|
connection: Optional["Connection"] = None,
|
|
120
164
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
165
|
+
**kwargs: Any,
|
|
121
166
|
) -> "Optional[Union[ModelDTOT, dict[str, Any]]]":
|
|
122
167
|
"""Fetch one row from the database.
|
|
123
168
|
|
|
@@ -125,7 +170,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
125
170
|
The first row of the query results.
|
|
126
171
|
"""
|
|
127
172
|
connection = self._connection(connection)
|
|
128
|
-
sql, parameters = self._process_sql_params(sql, parameters)
|
|
173
|
+
sql, parameters = self._process_sql_params(sql, parameters, **kwargs)
|
|
129
174
|
async with self._with_cursor(connection) as cursor:
|
|
130
175
|
await cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
131
176
|
result = await cursor.fetchone() # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType]
|
|
@@ -136,13 +181,37 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
136
181
|
return dict(zip(column_names, result)) # pyright: ignore[reportUnknownArgumentType, reportUnknownVariableType]
|
|
137
182
|
return cast("ModelDTOT", schema_type(**dict(zip(column_names, result)))) # pyright: ignore[reportUnknownArgumentType]
|
|
138
183
|
|
|
184
|
+
@overload
|
|
185
|
+
async def select_value(
|
|
186
|
+
self,
|
|
187
|
+
sql: str,
|
|
188
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
189
|
+
/,
|
|
190
|
+
*,
|
|
191
|
+
connection: "Optional[Connection]" = None,
|
|
192
|
+
schema_type: None = None,
|
|
193
|
+
**kwargs: Any,
|
|
194
|
+
) -> "Any": ...
|
|
195
|
+
@overload
|
|
196
|
+
async def select_value(
|
|
197
|
+
self,
|
|
198
|
+
sql: str,
|
|
199
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
200
|
+
/,
|
|
201
|
+
*,
|
|
202
|
+
connection: "Optional[Connection]" = None,
|
|
203
|
+
schema_type: "type[T]",
|
|
204
|
+
**kwargs: Any,
|
|
205
|
+
) -> "T": ...
|
|
139
206
|
async def select_value(
|
|
140
207
|
self,
|
|
141
208
|
sql: str,
|
|
142
209
|
parameters: "Optional[StatementParameterType]" = None,
|
|
143
210
|
/,
|
|
211
|
+
*,
|
|
144
212
|
connection: "Optional[Connection]" = None,
|
|
145
213
|
schema_type: "Optional[type[T]]" = None,
|
|
214
|
+
**kwargs: Any,
|
|
146
215
|
) -> "Union[T, Any]":
|
|
147
216
|
"""Fetch a single value from the database.
|
|
148
217
|
|
|
@@ -150,7 +219,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
150
219
|
The first value from the first row of results, or None if no results.
|
|
151
220
|
"""
|
|
152
221
|
connection = self._connection(connection)
|
|
153
|
-
sql, parameters = self._process_sql_params(sql, parameters)
|
|
222
|
+
sql, parameters = self._process_sql_params(sql, parameters, **kwargs)
|
|
154
223
|
async with self._with_cursor(connection) as cursor:
|
|
155
224
|
await cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
156
225
|
result = await cursor.fetchone() # pyright: ignore[reportUnknownMemberType]
|
|
@@ -159,13 +228,37 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
159
228
|
return result[0]
|
|
160
229
|
return schema_type(result[0]) # type: ignore[call-arg]
|
|
161
230
|
|
|
231
|
+
@overload
|
|
232
|
+
async def select_value_or_none(
|
|
233
|
+
self,
|
|
234
|
+
sql: str,
|
|
235
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
236
|
+
/,
|
|
237
|
+
*,
|
|
238
|
+
connection: "Optional[Connection]" = None,
|
|
239
|
+
schema_type: None = None,
|
|
240
|
+
**kwargs: Any,
|
|
241
|
+
) -> "Optional[Any]": ...
|
|
242
|
+
@overload
|
|
243
|
+
async def select_value_or_none(
|
|
244
|
+
self,
|
|
245
|
+
sql: str,
|
|
246
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
247
|
+
/,
|
|
248
|
+
*,
|
|
249
|
+
connection: "Optional[Connection]" = None,
|
|
250
|
+
schema_type: "type[T]",
|
|
251
|
+
**kwargs: Any,
|
|
252
|
+
) -> "Optional[T]": ...
|
|
162
253
|
async def select_value_or_none(
|
|
163
254
|
self,
|
|
164
255
|
sql: str,
|
|
165
256
|
parameters: "Optional[StatementParameterType]" = None,
|
|
166
257
|
/,
|
|
258
|
+
*,
|
|
167
259
|
connection: "Optional[Connection]" = None,
|
|
168
260
|
schema_type: "Optional[type[T]]" = None,
|
|
261
|
+
**kwargs: Any,
|
|
169
262
|
) -> "Optional[Union[T, Any]]":
|
|
170
263
|
"""Fetch a single value from the database.
|
|
171
264
|
|
|
@@ -173,8 +266,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
173
266
|
The first value from the first row of results, or None if no results.
|
|
174
267
|
"""
|
|
175
268
|
connection = self._connection(connection)
|
|
176
|
-
sql, parameters = self._process_sql_params(sql, parameters)
|
|
177
|
-
|
|
269
|
+
sql, parameters = self._process_sql_params(sql, parameters, **kwargs)
|
|
178
270
|
async with self._with_cursor(connection) as cursor:
|
|
179
271
|
await cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
180
272
|
result = await cursor.fetchone() # pyright: ignore[reportUnknownMemberType]
|
|
@@ -189,7 +281,9 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
189
281
|
sql: str,
|
|
190
282
|
parameters: Optional["StatementParameterType"] = None,
|
|
191
283
|
/,
|
|
284
|
+
*,
|
|
192
285
|
connection: Optional["Connection"] = None,
|
|
286
|
+
**kwargs: Any,
|
|
193
287
|
) -> int:
|
|
194
288
|
"""Insert, update, or delete data from the database.
|
|
195
289
|
|
|
@@ -197,19 +291,43 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
197
291
|
Row count affected by the operation.
|
|
198
292
|
"""
|
|
199
293
|
connection = self._connection(connection)
|
|
200
|
-
sql, parameters = self._process_sql_params(sql, parameters)
|
|
294
|
+
sql, parameters = self._process_sql_params(sql, parameters, **kwargs)
|
|
201
295
|
|
|
202
296
|
async with self._with_cursor(connection) as cursor:
|
|
203
297
|
await cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
204
298
|
return cursor.rowcount if hasattr(cursor, "rowcount") else -1 # pyright: ignore[reportUnknownVariableType, reportGeneralTypeIssues]
|
|
205
299
|
|
|
300
|
+
@overload
|
|
301
|
+
async def insert_update_delete_returning(
|
|
302
|
+
self,
|
|
303
|
+
sql: str,
|
|
304
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
305
|
+
/,
|
|
306
|
+
*,
|
|
307
|
+
connection: "Optional[Connection]" = None,
|
|
308
|
+
schema_type: None = None,
|
|
309
|
+
**kwargs: Any,
|
|
310
|
+
) -> "dict[str, Any]": ...
|
|
311
|
+
@overload
|
|
312
|
+
async def insert_update_delete_returning(
|
|
313
|
+
self,
|
|
314
|
+
sql: str,
|
|
315
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
316
|
+
/,
|
|
317
|
+
*,
|
|
318
|
+
connection: "Optional[Connection]" = None,
|
|
319
|
+
schema_type: "type[ModelDTOT]",
|
|
320
|
+
**kwargs: Any,
|
|
321
|
+
) -> "ModelDTOT": ...
|
|
206
322
|
async def insert_update_delete_returning(
|
|
207
323
|
self,
|
|
208
324
|
sql: str,
|
|
209
325
|
parameters: Optional["StatementParameterType"] = None,
|
|
210
326
|
/,
|
|
327
|
+
*,
|
|
211
328
|
connection: Optional["Connection"] = None,
|
|
212
329
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
330
|
+
**kwargs: Any,
|
|
213
331
|
) -> "Optional[Union[dict[str, Any], ModelDTOT]]":
|
|
214
332
|
"""Insert, update, or delete data from the database and return result.
|
|
215
333
|
|
|
@@ -217,7 +335,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
217
335
|
The first row of results.
|
|
218
336
|
"""
|
|
219
337
|
connection = self._connection(connection)
|
|
220
|
-
sql, parameters = self._process_sql_params(sql, parameters)
|
|
338
|
+
sql, parameters = self._process_sql_params(sql, parameters, **kwargs)
|
|
221
339
|
|
|
222
340
|
async with self._with_cursor(connection) as cursor:
|
|
223
341
|
await cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
@@ -234,7 +352,9 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
234
352
|
sql: str,
|
|
235
353
|
parameters: Optional["StatementParameterType"] = None,
|
|
236
354
|
/,
|
|
355
|
+
*,
|
|
237
356
|
connection: Optional["Connection"] = None,
|
|
357
|
+
**kwargs: Any,
|
|
238
358
|
) -> str:
|
|
239
359
|
"""Execute a script.
|
|
240
360
|
|
|
@@ -242,7 +362,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
242
362
|
Status message for the operation.
|
|
243
363
|
"""
|
|
244
364
|
connection = self._connection(connection)
|
|
245
|
-
sql, parameters = self._process_sql_params(sql, parameters)
|
|
365
|
+
sql, parameters = self._process_sql_params(sql, parameters, **kwargs)
|
|
246
366
|
|
|
247
367
|
async with self._with_cursor(connection) as cursor:
|
|
248
368
|
await cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
@@ -253,8 +373,10 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
253
373
|
sql: str,
|
|
254
374
|
parameters: Optional["StatementParameterType"] = None,
|
|
255
375
|
/,
|
|
376
|
+
*,
|
|
256
377
|
connection: Optional["Connection"] = None,
|
|
257
378
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
379
|
+
**kwargs: Any,
|
|
258
380
|
) -> "Optional[Union[dict[str, Any], ModelDTOT]]":
|
|
259
381
|
"""Execute a script and return result.
|
|
260
382
|
|
|
@@ -262,7 +384,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
262
384
|
The first row of results.
|
|
263
385
|
"""
|
|
264
386
|
connection = self._connection(connection)
|
|
265
|
-
sql, parameters = self._process_sql_params(sql, parameters)
|
|
387
|
+
sql, parameters = self._process_sql_params(sql, parameters, **kwargs)
|
|
266
388
|
|
|
267
389
|
async with self._with_cursor(connection) as cursor:
|
|
268
390
|
await cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from sqlspec.adapters.asyncmy.config import
|
|
1
|
+
from sqlspec.adapters.asyncmy.config import AsyncmyConfig, AsyncmyPoolConfig
|
|
2
2
|
from sqlspec.adapters.asyncmy.driver import AsyncmyDriver # type: ignore[attr-defined]
|
|
3
3
|
|
|
4
4
|
__all__ = (
|
|
5
|
-
"
|
|
5
|
+
"AsyncmyConfig",
|
|
6
6
|
"AsyncmyDriver",
|
|
7
|
-
"
|
|
7
|
+
"AsyncmyPoolConfig",
|
|
8
8
|
)
|
|
@@ -16,8 +16,8 @@ if TYPE_CHECKING:
|
|
|
16
16
|
from asyncmy.pool import Pool # pyright: ignore[reportUnknownVariableType]
|
|
17
17
|
|
|
18
18
|
__all__ = (
|
|
19
|
-
"
|
|
20
|
-
"
|
|
19
|
+
"AsyncmyConfig",
|
|
20
|
+
"AsyncmyPoolConfig",
|
|
21
21
|
)
|
|
22
22
|
|
|
23
23
|
|
|
@@ -25,7 +25,7 @@ T = TypeVar("T")
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
@dataclass
|
|
28
|
-
class
|
|
28
|
+
class AsyncmyPoolConfig(GenericPoolConfig):
|
|
29
29
|
"""Configuration for Asyncmy's connection pool.
|
|
30
30
|
|
|
31
31
|
This class provides configuration options for Asyncmy database connection pools.
|
|
@@ -104,19 +104,19 @@ class AsyncmyPool(GenericPoolConfig):
|
|
|
104
104
|
|
|
105
105
|
|
|
106
106
|
@dataclass
|
|
107
|
-
class
|
|
107
|
+
class AsyncmyConfig(AsyncDatabaseConfig["Connection", "Pool", "AsyncmyDriver"]):
|
|
108
108
|
"""Asyncmy Configuration."""
|
|
109
109
|
|
|
110
110
|
__is_async__ = True
|
|
111
111
|
__supports_connection_pooling__ = True
|
|
112
112
|
|
|
113
|
-
pool_config: "Optional[
|
|
113
|
+
pool_config: "Optional[AsyncmyPoolConfig]" = None
|
|
114
114
|
"""Asyncmy Pool configuration"""
|
|
115
|
-
connection_type: "type[Connection]" = field(init=False, default_factory=lambda: Connection) # pyright: ignore
|
|
115
|
+
connection_type: "type[Connection]" = field(hash=False, init=False, default_factory=lambda: Connection) # pyright: ignore
|
|
116
116
|
"""Type of the connection object"""
|
|
117
|
-
driver_type: "type[AsyncmyDriver]" = field(init=False, default_factory=lambda: AsyncmyDriver)
|
|
117
|
+
driver_type: "type[AsyncmyDriver]" = field(hash=False, init=False, default_factory=lambda: AsyncmyDriver)
|
|
118
118
|
"""Type of the driver object"""
|
|
119
|
-
pool_instance: "Optional[Pool]" = None # pyright: ignore[reportUnknownVariableType]
|
|
119
|
+
pool_instance: "Optional[Pool]" = field(hash=False, default=None) # pyright: ignore[reportUnknownVariableType]
|
|
120
120
|
"""Instance of the pool"""
|
|
121
121
|
|
|
122
122
|
@property
|
|
@@ -162,7 +162,7 @@ class Asyncmy(AsyncDatabaseConfig["Connection", "Pool", "AsyncmyDriver"]):
|
|
|
162
162
|
raise ImproperConfigurationError(msg)
|
|
163
163
|
|
|
164
164
|
async def create_connection(self) -> "Connection": # pyright: ignore[reportUnknownParameterType]
|
|
165
|
-
"""Create and return a new asyncmy connection.
|
|
165
|
+
"""Create and return a new asyncmy connection from the pool.
|
|
166
166
|
|
|
167
167
|
Returns:
|
|
168
168
|
A Connection instance.
|
|
@@ -171,9 +171,8 @@ class Asyncmy(AsyncDatabaseConfig["Connection", "Pool", "AsyncmyDriver"]):
|
|
|
171
171
|
ImproperConfigurationError: If the connection could not be created.
|
|
172
172
|
"""
|
|
173
173
|
try:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return await asyncmy.connect(**self.connection_config_dict) # pyright: ignore
|
|
174
|
+
async with self.provide_connection() as conn:
|
|
175
|
+
return conn
|
|
177
176
|
except Exception as e:
|
|
178
177
|
msg = f"Could not configure the Asyncmy connection. Error: {e!s}"
|
|
179
178
|
raise ImproperConfigurationError(msg) from e
|