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,54 +1,78 @@
|
|
|
1
1
|
from contextlib import asynccontextmanager, contextmanager
|
|
2
|
-
from typing import TYPE_CHECKING, Any, Optional, Union, cast
|
|
2
|
+
from typing import TYPE_CHECKING, Any, Optional, Union, cast, overload
|
|
3
3
|
|
|
4
|
-
from
|
|
5
|
-
AsyncArrowBulkOperationsMixin,
|
|
6
|
-
AsyncDriverAdapterProtocol,
|
|
7
|
-
SyncArrowBulkOperationsMixin,
|
|
8
|
-
SyncDriverAdapterProtocol,
|
|
9
|
-
T,
|
|
10
|
-
)
|
|
11
|
-
from sqlspec.typing import ArrowTable, StatementParameterType
|
|
4
|
+
from oracledb import AsyncConnection, AsyncCursor, Connection, Cursor
|
|
12
5
|
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
from sqlspec.base import AsyncDriverAdapterProtocol, SyncDriverAdapterProtocol
|
|
7
|
+
from sqlspec.mixins import AsyncArrowBulkOperationsMixin, SQLTranslatorMixin, SyncArrowBulkOperationsMixin
|
|
8
|
+
from sqlspec.typing import ArrowTable, StatementParameterType, T
|
|
15
9
|
|
|
16
|
-
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from collections.abc import AsyncGenerator, Generator, Sequence
|
|
17
12
|
|
|
18
|
-
# Conditionally import ArrowTable for type checking
|
|
19
13
|
from sqlspec.typing import ModelDTOT
|
|
20
14
|
|
|
21
|
-
__all__ = ("OracleAsyncDriver", "OracleSyncDriver")
|
|
15
|
+
__all__ = ("OracleAsyncConnection", "OracleAsyncDriver", "OracleSyncConnection", "OracleSyncDriver")
|
|
16
|
+
|
|
17
|
+
OracleSyncConnection = Connection
|
|
18
|
+
OracleAsyncConnection = AsyncConnection
|
|
22
19
|
|
|
23
20
|
|
|
24
|
-
class OracleSyncDriver(
|
|
21
|
+
class OracleSyncDriver(
|
|
22
|
+
SyncArrowBulkOperationsMixin["OracleSyncConnection"],
|
|
23
|
+
SQLTranslatorMixin["OracleSyncConnection"],
|
|
24
|
+
SyncDriverAdapterProtocol["OracleSyncConnection"],
|
|
25
|
+
):
|
|
25
26
|
"""Oracle Sync Driver Adapter."""
|
|
26
27
|
|
|
27
|
-
connection: "
|
|
28
|
+
connection: "OracleSyncConnection"
|
|
28
29
|
dialect: str = "oracle"
|
|
29
30
|
|
|
30
|
-
def __init__(self, connection: "
|
|
31
|
+
def __init__(self, connection: "OracleSyncConnection") -> None:
|
|
31
32
|
self.connection = connection
|
|
32
33
|
|
|
33
34
|
@staticmethod
|
|
34
35
|
@contextmanager
|
|
35
|
-
def _with_cursor(connection: "
|
|
36
|
+
def _with_cursor(connection: "OracleSyncConnection") -> "Generator[Cursor, None, None]":
|
|
36
37
|
cursor = connection.cursor()
|
|
37
38
|
try:
|
|
38
39
|
yield cursor
|
|
39
40
|
finally:
|
|
40
41
|
cursor.close()
|
|
41
42
|
|
|
43
|
+
# --- Public API Methods --- #
|
|
44
|
+
@overload
|
|
45
|
+
def select(
|
|
46
|
+
self,
|
|
47
|
+
sql: str,
|
|
48
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
49
|
+
/,
|
|
50
|
+
*,
|
|
51
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
52
|
+
schema_type: None = None,
|
|
53
|
+
**kwargs: Any,
|
|
54
|
+
) -> "Sequence[dict[str, Any]]": ...
|
|
55
|
+
@overload
|
|
42
56
|
def select(
|
|
43
57
|
self,
|
|
44
58
|
sql: str,
|
|
45
59
|
parameters: "Optional[StatementParameterType]" = None,
|
|
46
60
|
/,
|
|
47
61
|
*,
|
|
48
|
-
connection: "Optional[
|
|
62
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
63
|
+
schema_type: "type[ModelDTOT]",
|
|
64
|
+
**kwargs: Any,
|
|
65
|
+
) -> "Sequence[ModelDTOT]": ...
|
|
66
|
+
def select(
|
|
67
|
+
self,
|
|
68
|
+
sql: str,
|
|
69
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
70
|
+
/,
|
|
71
|
+
*,
|
|
72
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
49
73
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
50
74
|
**kwargs: Any,
|
|
51
|
-
) -> "
|
|
75
|
+
) -> "Sequence[Union[ModelDTOT, dict[str, Any]]]":
|
|
52
76
|
"""Fetch data from the database.
|
|
53
77
|
|
|
54
78
|
Args:
|
|
@@ -76,13 +100,35 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
76
100
|
|
|
77
101
|
return [dict(zip(column_names, row)) for row in results] # pyright: ignore
|
|
78
102
|
|
|
103
|
+
@overload
|
|
79
104
|
def select_one(
|
|
80
105
|
self,
|
|
81
106
|
sql: str,
|
|
82
107
|
parameters: "Optional[StatementParameterType]" = None,
|
|
83
108
|
/,
|
|
84
109
|
*,
|
|
85
|
-
connection: "Optional[
|
|
110
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
111
|
+
schema_type: None = None,
|
|
112
|
+
**kwargs: Any,
|
|
113
|
+
) -> "dict[str, Any]": ...
|
|
114
|
+
@overload
|
|
115
|
+
def select_one(
|
|
116
|
+
self,
|
|
117
|
+
sql: str,
|
|
118
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
119
|
+
/,
|
|
120
|
+
*,
|
|
121
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
122
|
+
schema_type: "type[ModelDTOT]",
|
|
123
|
+
**kwargs: Any,
|
|
124
|
+
) -> "ModelDTOT": ...
|
|
125
|
+
def select_one(
|
|
126
|
+
self,
|
|
127
|
+
sql: str,
|
|
128
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
129
|
+
/,
|
|
130
|
+
*,
|
|
131
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
86
132
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
87
133
|
**kwargs: Any,
|
|
88
134
|
) -> "Union[ModelDTOT, dict[str, Any]]":
|
|
@@ -114,13 +160,35 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
114
160
|
# Always return dictionaries
|
|
115
161
|
return dict(zip(column_names, result)) # pyright: ignore[reportUnknownArgumentType,reportUnknownVariableType]
|
|
116
162
|
|
|
163
|
+
@overload
|
|
164
|
+
def select_one_or_none(
|
|
165
|
+
self,
|
|
166
|
+
sql: str,
|
|
167
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
168
|
+
/,
|
|
169
|
+
*,
|
|
170
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
171
|
+
schema_type: None = None,
|
|
172
|
+
**kwargs: Any,
|
|
173
|
+
) -> "Optional[dict[str, Any]]": ...
|
|
174
|
+
@overload
|
|
175
|
+
def select_one_or_none(
|
|
176
|
+
self,
|
|
177
|
+
sql: str,
|
|
178
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
179
|
+
/,
|
|
180
|
+
*,
|
|
181
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
182
|
+
schema_type: "type[ModelDTOT]",
|
|
183
|
+
**kwargs: Any,
|
|
184
|
+
) -> "Optional[ModelDTOT]": ...
|
|
117
185
|
def select_one_or_none(
|
|
118
186
|
self,
|
|
119
187
|
sql: str,
|
|
120
188
|
parameters: "Optional[StatementParameterType]" = None,
|
|
121
189
|
/,
|
|
122
190
|
*,
|
|
123
|
-
connection: "Optional[
|
|
191
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
124
192
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
125
193
|
**kwargs: Any,
|
|
126
194
|
) -> "Optional[Union[ModelDTOT, dict[str, Any]]]":
|
|
@@ -147,13 +215,35 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
147
215
|
# Always return dictionaries
|
|
148
216
|
return dict(zip(column_names, result)) # pyright: ignore[reportUnknownArgumentType,reportUnknownVariableType]
|
|
149
217
|
|
|
218
|
+
@overload
|
|
219
|
+
def select_value(
|
|
220
|
+
self,
|
|
221
|
+
sql: str,
|
|
222
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
223
|
+
/,
|
|
224
|
+
*,
|
|
225
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
226
|
+
schema_type: None = None,
|
|
227
|
+
**kwargs: Any,
|
|
228
|
+
) -> "Any": ...
|
|
229
|
+
@overload
|
|
230
|
+
def select_value(
|
|
231
|
+
self,
|
|
232
|
+
sql: str,
|
|
233
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
234
|
+
/,
|
|
235
|
+
*,
|
|
236
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
237
|
+
schema_type: "type[T]",
|
|
238
|
+
**kwargs: Any,
|
|
239
|
+
) -> "T": ...
|
|
150
240
|
def select_value(
|
|
151
241
|
self,
|
|
152
242
|
sql: str,
|
|
153
243
|
parameters: "Optional[StatementParameterType]" = None,
|
|
154
244
|
/,
|
|
155
245
|
*,
|
|
156
|
-
connection: "Optional[
|
|
246
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
157
247
|
schema_type: "Optional[type[T]]" = None,
|
|
158
248
|
**kwargs: Any,
|
|
159
249
|
) -> "Union[T, Any]":
|
|
@@ -174,13 +264,35 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
174
264
|
return result[0] # pyright: ignore[reportUnknownArgumentType]
|
|
175
265
|
return schema_type(result[0]) # type: ignore[call-arg]
|
|
176
266
|
|
|
267
|
+
@overload
|
|
177
268
|
def select_value_or_none(
|
|
178
269
|
self,
|
|
179
270
|
sql: str,
|
|
180
271
|
parameters: "Optional[StatementParameterType]" = None,
|
|
181
272
|
/,
|
|
182
273
|
*,
|
|
183
|
-
connection: "Optional[
|
|
274
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
275
|
+
schema_type: None = None,
|
|
276
|
+
**kwargs: Any,
|
|
277
|
+
) -> "Optional[Any]": ...
|
|
278
|
+
@overload
|
|
279
|
+
def select_value_or_none(
|
|
280
|
+
self,
|
|
281
|
+
sql: str,
|
|
282
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
283
|
+
/,
|
|
284
|
+
*,
|
|
285
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
286
|
+
schema_type: "type[T]",
|
|
287
|
+
**kwargs: Any,
|
|
288
|
+
) -> "Optional[T]": ...
|
|
289
|
+
def select_value_or_none(
|
|
290
|
+
self,
|
|
291
|
+
sql: str,
|
|
292
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
293
|
+
/,
|
|
294
|
+
*,
|
|
295
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
184
296
|
schema_type: "Optional[type[T]]" = None,
|
|
185
297
|
**kwargs: Any,
|
|
186
298
|
) -> "Optional[Union[T, Any]]":
|
|
@@ -209,7 +321,7 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
209
321
|
parameters: "Optional[StatementParameterType]" = None,
|
|
210
322
|
/,
|
|
211
323
|
*,
|
|
212
|
-
connection: "Optional[
|
|
324
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
213
325
|
**kwargs: Any,
|
|
214
326
|
) -> int:
|
|
215
327
|
"""Insert, update, or delete data from the database.
|
|
@@ -224,13 +336,35 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
224
336
|
cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
225
337
|
return cursor.rowcount # pyright: ignore[reportUnknownMemberType]
|
|
226
338
|
|
|
339
|
+
@overload
|
|
340
|
+
def insert_update_delete_returning(
|
|
341
|
+
self,
|
|
342
|
+
sql: str,
|
|
343
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
344
|
+
/,
|
|
345
|
+
*,
|
|
346
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
347
|
+
schema_type: None = None,
|
|
348
|
+
**kwargs: Any,
|
|
349
|
+
) -> "dict[str, Any]": ...
|
|
350
|
+
@overload
|
|
351
|
+
def insert_update_delete_returning(
|
|
352
|
+
self,
|
|
353
|
+
sql: str,
|
|
354
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
355
|
+
/,
|
|
356
|
+
*,
|
|
357
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
358
|
+
schema_type: "type[ModelDTOT]",
|
|
359
|
+
**kwargs: Any,
|
|
360
|
+
) -> "ModelDTOT": ...
|
|
227
361
|
def insert_update_delete_returning(
|
|
228
362
|
self,
|
|
229
363
|
sql: str,
|
|
230
364
|
parameters: "Optional[StatementParameterType]" = None,
|
|
231
365
|
/,
|
|
232
366
|
*,
|
|
233
|
-
connection: "Optional[
|
|
367
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
234
368
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
235
369
|
**kwargs: Any,
|
|
236
370
|
) -> "Optional[Union[dict[str, Any], ModelDTOT]]":
|
|
@@ -263,7 +397,7 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
263
397
|
parameters: "Optional[StatementParameterType]" = None,
|
|
264
398
|
/,
|
|
265
399
|
*,
|
|
266
|
-
connection: "Optional[
|
|
400
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
267
401
|
**kwargs: Any,
|
|
268
402
|
) -> str:
|
|
269
403
|
"""Execute a script.
|
|
@@ -284,7 +418,7 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
284
418
|
parameters: "Optional[StatementParameterType]" = None,
|
|
285
419
|
/,
|
|
286
420
|
*,
|
|
287
|
-
connection: "Optional[
|
|
421
|
+
connection: "Optional[OracleSyncConnection]" = None,
|
|
288
422
|
**kwargs: Any,
|
|
289
423
|
) -> "ArrowTable": # pyright: ignore[reportUnknownVariableType]
|
|
290
424
|
"""Execute a SQL query and return results as an Apache Arrow Table.
|
|
@@ -300,35 +434,60 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
300
434
|
|
|
301
435
|
|
|
302
436
|
class OracleAsyncDriver(
|
|
303
|
-
AsyncArrowBulkOperationsMixin["
|
|
437
|
+
AsyncArrowBulkOperationsMixin["OracleAsyncConnection"],
|
|
438
|
+
SQLTranslatorMixin["OracleAsyncConnection"],
|
|
439
|
+
AsyncDriverAdapterProtocol["OracleAsyncConnection"],
|
|
304
440
|
):
|
|
305
441
|
"""Oracle Async Driver Adapter."""
|
|
306
442
|
|
|
307
|
-
connection: "
|
|
443
|
+
connection: "OracleAsyncConnection"
|
|
308
444
|
dialect: str = "oracle"
|
|
309
445
|
|
|
310
|
-
def __init__(self, connection: "
|
|
446
|
+
def __init__(self, connection: "OracleAsyncConnection") -> None:
|
|
311
447
|
self.connection = connection
|
|
312
448
|
|
|
313
449
|
@staticmethod
|
|
314
450
|
@asynccontextmanager
|
|
315
|
-
async def _with_cursor(connection: "
|
|
451
|
+
async def _with_cursor(connection: "OracleAsyncConnection") -> "AsyncGenerator[AsyncCursor, None]":
|
|
316
452
|
cursor = connection.cursor()
|
|
317
453
|
try:
|
|
318
454
|
yield cursor
|
|
319
455
|
finally:
|
|
320
456
|
cursor.close()
|
|
321
457
|
|
|
458
|
+
# --- Public API Methods --- #
|
|
459
|
+
@overload
|
|
460
|
+
async def select(
|
|
461
|
+
self,
|
|
462
|
+
sql: str,
|
|
463
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
464
|
+
/,
|
|
465
|
+
*,
|
|
466
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
467
|
+
schema_type: None = None,
|
|
468
|
+
**kwargs: Any,
|
|
469
|
+
) -> "Sequence[dict[str, Any]]": ...
|
|
470
|
+
@overload
|
|
471
|
+
async def select(
|
|
472
|
+
self,
|
|
473
|
+
sql: str,
|
|
474
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
475
|
+
/,
|
|
476
|
+
*,
|
|
477
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
478
|
+
schema_type: "type[ModelDTOT]",
|
|
479
|
+
**kwargs: Any,
|
|
480
|
+
) -> "Sequence[ModelDTOT]": ...
|
|
322
481
|
async def select(
|
|
323
482
|
self,
|
|
324
483
|
sql: str,
|
|
325
484
|
parameters: "Optional[StatementParameterType]" = None,
|
|
326
485
|
/,
|
|
327
486
|
*,
|
|
328
|
-
connection: "Optional[
|
|
487
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
329
488
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
330
489
|
**kwargs: Any,
|
|
331
|
-
) -> "
|
|
490
|
+
) -> "Sequence[Union[ModelDTOT, dict[str, Any]]]":
|
|
332
491
|
"""Fetch data from the database.
|
|
333
492
|
|
|
334
493
|
Returns:
|
|
@@ -350,13 +509,35 @@ class OracleAsyncDriver(
|
|
|
350
509
|
|
|
351
510
|
return [dict(zip(column_names, row)) for row in results] # pyright: ignore
|
|
352
511
|
|
|
512
|
+
@overload
|
|
353
513
|
async def select_one(
|
|
354
514
|
self,
|
|
355
515
|
sql: str,
|
|
356
516
|
parameters: "Optional[StatementParameterType]" = None,
|
|
357
517
|
/,
|
|
358
518
|
*,
|
|
359
|
-
connection: "Optional[
|
|
519
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
520
|
+
schema_type: None = None,
|
|
521
|
+
**kwargs: Any,
|
|
522
|
+
) -> "dict[str, Any]": ...
|
|
523
|
+
@overload
|
|
524
|
+
async def select_one(
|
|
525
|
+
self,
|
|
526
|
+
sql: str,
|
|
527
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
528
|
+
/,
|
|
529
|
+
*,
|
|
530
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
531
|
+
schema_type: "type[ModelDTOT]",
|
|
532
|
+
**kwargs: Any,
|
|
533
|
+
) -> "ModelDTOT": ...
|
|
534
|
+
async def select_one(
|
|
535
|
+
self,
|
|
536
|
+
sql: str,
|
|
537
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
538
|
+
/,
|
|
539
|
+
*,
|
|
540
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
360
541
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
361
542
|
**kwargs: Any,
|
|
362
543
|
) -> "Union[ModelDTOT, dict[str, Any]]":
|
|
@@ -380,13 +561,35 @@ class OracleAsyncDriver(
|
|
|
380
561
|
# Always return dictionaries
|
|
381
562
|
return dict(zip(column_names, result)) # pyright: ignore[reportUnknownArgumentType,reportUnknownVariableType]
|
|
382
563
|
|
|
564
|
+
@overload
|
|
565
|
+
async def select_one_or_none(
|
|
566
|
+
self,
|
|
567
|
+
sql: str,
|
|
568
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
569
|
+
/,
|
|
570
|
+
*,
|
|
571
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
572
|
+
schema_type: None = None,
|
|
573
|
+
**kwargs: Any,
|
|
574
|
+
) -> "Optional[dict[str, Any]]": ...
|
|
575
|
+
@overload
|
|
576
|
+
async def select_one_or_none(
|
|
577
|
+
self,
|
|
578
|
+
sql: str,
|
|
579
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
580
|
+
/,
|
|
581
|
+
*,
|
|
582
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
583
|
+
schema_type: "type[ModelDTOT]",
|
|
584
|
+
**kwargs: Any,
|
|
585
|
+
) -> "Optional[ModelDTOT]": ...
|
|
383
586
|
async def select_one_or_none(
|
|
384
587
|
self,
|
|
385
588
|
sql: str,
|
|
386
589
|
parameters: "Optional[StatementParameterType]" = None,
|
|
387
590
|
/,
|
|
388
591
|
*,
|
|
389
|
-
connection: "Optional[
|
|
592
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
390
593
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
391
594
|
**kwargs: Any,
|
|
392
595
|
) -> "Optional[Union[ModelDTOT, dict[str, Any]]]":
|
|
@@ -413,13 +616,35 @@ class OracleAsyncDriver(
|
|
|
413
616
|
# Always return dictionaries
|
|
414
617
|
return dict(zip(column_names, result)) # pyright: ignore[reportUnknownArgumentType,reportUnknownVariableType]
|
|
415
618
|
|
|
619
|
+
@overload
|
|
620
|
+
async def select_value(
|
|
621
|
+
self,
|
|
622
|
+
sql: str,
|
|
623
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
624
|
+
/,
|
|
625
|
+
*,
|
|
626
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
627
|
+
schema_type: None = None,
|
|
628
|
+
**kwargs: Any,
|
|
629
|
+
) -> "Any": ...
|
|
630
|
+
@overload
|
|
631
|
+
async def select_value(
|
|
632
|
+
self,
|
|
633
|
+
sql: str,
|
|
634
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
635
|
+
/,
|
|
636
|
+
*,
|
|
637
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
638
|
+
schema_type: "type[T]",
|
|
639
|
+
**kwargs: Any,
|
|
640
|
+
) -> "T": ...
|
|
416
641
|
async def select_value(
|
|
417
642
|
self,
|
|
418
643
|
sql: str,
|
|
419
644
|
parameters: "Optional[StatementParameterType]" = None,
|
|
420
645
|
/,
|
|
421
646
|
*,
|
|
422
|
-
connection: "Optional[
|
|
647
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
423
648
|
schema_type: "Optional[type[T]]" = None,
|
|
424
649
|
**kwargs: Any,
|
|
425
650
|
) -> "Union[T, Any]":
|
|
@@ -440,13 +665,35 @@ class OracleAsyncDriver(
|
|
|
440
665
|
return result[0] # pyright: ignore[reportUnknownArgumentType]
|
|
441
666
|
return schema_type(result[0]) # type: ignore[call-arg]
|
|
442
667
|
|
|
668
|
+
@overload
|
|
669
|
+
async def select_value_or_none(
|
|
670
|
+
self,
|
|
671
|
+
sql: str,
|
|
672
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
673
|
+
/,
|
|
674
|
+
*,
|
|
675
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
676
|
+
schema_type: None = None,
|
|
677
|
+
**kwargs: Any,
|
|
678
|
+
) -> "Optional[Any]": ...
|
|
679
|
+
@overload
|
|
443
680
|
async def select_value_or_none(
|
|
444
681
|
self,
|
|
445
682
|
sql: str,
|
|
446
683
|
parameters: "Optional[StatementParameterType]" = None,
|
|
447
684
|
/,
|
|
448
685
|
*,
|
|
449
|
-
connection: "Optional[
|
|
686
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
687
|
+
schema_type: "type[T]",
|
|
688
|
+
**kwargs: Any,
|
|
689
|
+
) -> "Optional[T]": ...
|
|
690
|
+
async def select_value_or_none(
|
|
691
|
+
self,
|
|
692
|
+
sql: str,
|
|
693
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
694
|
+
/,
|
|
695
|
+
*,
|
|
696
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
450
697
|
schema_type: "Optional[type[T]]" = None,
|
|
451
698
|
**kwargs: Any,
|
|
452
699
|
) -> "Optional[Union[T, Any]]":
|
|
@@ -475,7 +722,7 @@ class OracleAsyncDriver(
|
|
|
475
722
|
parameters: "Optional[StatementParameterType]" = None,
|
|
476
723
|
/,
|
|
477
724
|
*,
|
|
478
|
-
connection: "Optional[
|
|
725
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
479
726
|
**kwargs: Any,
|
|
480
727
|
) -> int:
|
|
481
728
|
"""Insert, update, or delete data from the database.
|
|
@@ -490,13 +737,35 @@ class OracleAsyncDriver(
|
|
|
490
737
|
await cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
491
738
|
return cursor.rowcount # pyright: ignore[reportUnknownMemberType]
|
|
492
739
|
|
|
740
|
+
@overload
|
|
741
|
+
async def insert_update_delete_returning(
|
|
742
|
+
self,
|
|
743
|
+
sql: str,
|
|
744
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
745
|
+
/,
|
|
746
|
+
*,
|
|
747
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
748
|
+
schema_type: None = None,
|
|
749
|
+
**kwargs: Any,
|
|
750
|
+
) -> "dict[str, Any]": ...
|
|
751
|
+
@overload
|
|
752
|
+
async def insert_update_delete_returning(
|
|
753
|
+
self,
|
|
754
|
+
sql: str,
|
|
755
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
756
|
+
/,
|
|
757
|
+
*,
|
|
758
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
759
|
+
schema_type: "type[ModelDTOT]",
|
|
760
|
+
**kwargs: Any,
|
|
761
|
+
) -> "ModelDTOT": ...
|
|
493
762
|
async def insert_update_delete_returning(
|
|
494
763
|
self,
|
|
495
764
|
sql: str,
|
|
496
765
|
parameters: "Optional[StatementParameterType]" = None,
|
|
497
766
|
/,
|
|
498
767
|
*,
|
|
499
|
-
connection: "Optional[
|
|
768
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
500
769
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
501
770
|
**kwargs: Any,
|
|
502
771
|
) -> "Optional[Union[dict[str, Any], ModelDTOT]]":
|
|
@@ -529,7 +798,7 @@ class OracleAsyncDriver(
|
|
|
529
798
|
parameters: "Optional[StatementParameterType]" = None,
|
|
530
799
|
/,
|
|
531
800
|
*,
|
|
532
|
-
connection: "Optional[
|
|
801
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
533
802
|
**kwargs: Any,
|
|
534
803
|
) -> str:
|
|
535
804
|
"""Execute a script.
|
|
@@ -550,7 +819,7 @@ class OracleAsyncDriver(
|
|
|
550
819
|
parameters: "Optional[StatementParameterType]" = None,
|
|
551
820
|
/,
|
|
552
821
|
*,
|
|
553
|
-
connection: "Optional[
|
|
822
|
+
connection: "Optional[OracleAsyncConnection]" = None,
|
|
554
823
|
**kwargs: Any,
|
|
555
824
|
) -> "ArrowTable": # pyright: ignore[reportUnknownVariableType]
|
|
556
825
|
"""Execute a SQL query asynchronously and return results as an Apache Arrow Table.
|
|
@@ -6,7 +6,7 @@ from typing import TYPE_CHECKING, Any, Optional, Union
|
|
|
6
6
|
|
|
7
7
|
from psqlpy import Connection, ConnectionPool
|
|
8
8
|
|
|
9
|
-
from sqlspec.adapters.psqlpy.driver import PsqlpyDriver
|
|
9
|
+
from sqlspec.adapters.psqlpy.driver import PsqlpyConnection, PsqlpyDriver
|
|
10
10
|
from sqlspec.base import AsyncDatabaseConfig, GenericPoolConfig
|
|
11
11
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
12
12
|
from sqlspec.typing import Empty, EmptyType, dataclass_to_dict
|
|
@@ -94,7 +94,7 @@ class PsqlpyPoolConfig(GenericPoolConfig):
|
|
|
94
94
|
|
|
95
95
|
|
|
96
96
|
@dataclass
|
|
97
|
-
class PsqlpyConfig(AsyncDatabaseConfig[
|
|
97
|
+
class PsqlpyConfig(AsyncDatabaseConfig[PsqlpyConnection, ConnectionPool, PsqlpyDriver]):
|
|
98
98
|
"""Configuration for psqlpy database connections, managing a connection pool.
|
|
99
99
|
|
|
100
100
|
This configuration class wraps `PsqlpyPoolConfig` and manages the lifecycle
|
|
@@ -105,7 +105,7 @@ class PsqlpyConfig(AsyncDatabaseConfig[Connection, ConnectionPool, PsqlpyDriver]
|
|
|
105
105
|
"""Psqlpy Pool configuration"""
|
|
106
106
|
driver_type: type[PsqlpyDriver] = field(default=PsqlpyDriver, init=False, hash=False)
|
|
107
107
|
"""Type of the driver object"""
|
|
108
|
-
connection_type: type[
|
|
108
|
+
connection_type: type[PsqlpyConnection] = field(default=PsqlpyConnection, init=False, hash=False)
|
|
109
109
|
"""Type of the connection object"""
|
|
110
110
|
pool_instance: Optional[ConnectionPool] = field(default=None, hash=False)
|
|
111
111
|
"""The connection pool instance. If set, this will be used instead of creating a new pool."""
|
|
@@ -204,33 +204,25 @@ class PsqlpyConfig(AsyncDatabaseConfig[Connection, ConnectionPool, PsqlpyDriver]
|
|
|
204
204
|
|
|
205
205
|
return _create()
|
|
206
206
|
|
|
207
|
-
def create_connection(self) -> "Awaitable[
|
|
207
|
+
def create_connection(self) -> "Awaitable[PsqlpyConnection]":
|
|
208
208
|
"""Create and return a new, standalone psqlpy connection using the configured parameters.
|
|
209
209
|
|
|
210
|
-
Note: This method is not supported by the psqlpy adapter as connection
|
|
211
|
-
creation is primarily handled via the ConnectionPool.
|
|
212
|
-
Use `provide_connection` or `provide_session` for pooled connections.
|
|
213
|
-
|
|
214
210
|
Returns:
|
|
215
211
|
An awaitable that resolves to a new Connection instance.
|
|
216
|
-
|
|
217
|
-
Raises:
|
|
218
|
-
NotImplementedError: This method is not implemented for psqlpy.
|
|
219
212
|
"""
|
|
220
213
|
|
|
221
214
|
async def _create() -> "Connection":
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
"
|
|
227
|
-
|
|
228
|
-
raise NotImplementedError(msg)
|
|
215
|
+
try:
|
|
216
|
+
async with self.provide_connection() as conn:
|
|
217
|
+
return conn
|
|
218
|
+
except Exception as e:
|
|
219
|
+
msg = f"Could not configure the psqlpy connection. Error: {e!s}"
|
|
220
|
+
raise ImproperConfigurationError(msg) from e
|
|
229
221
|
|
|
230
222
|
return _create()
|
|
231
223
|
|
|
232
224
|
@asynccontextmanager
|
|
233
|
-
async def provide_connection(self, *args: "Any", **kwargs: "Any") -> "AsyncGenerator[
|
|
225
|
+
async def provide_connection(self, *args: "Any", **kwargs: "Any") -> "AsyncGenerator[PsqlpyConnection, None]":
|
|
234
226
|
"""Acquire a connection from the pool.
|
|
235
227
|
|
|
236
228
|
Yields:
|