sqlspec 0.9.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/adapters/adbc/driver.py +135 -3
- sqlspec/adapters/aiosqlite/driver.py +136 -3
- sqlspec/adapters/asyncmy/driver.py +136 -3
- sqlspec/adapters/asyncpg/driver.py +136 -2
- sqlspec/adapters/duckdb/driver.py +141 -11
- sqlspec/adapters/oracledb/driver.py +270 -4
- sqlspec/adapters/psqlpy/config.py +6 -14
- sqlspec/adapters/psqlpy/driver.py +149 -3
- sqlspec/adapters/psycopg/driver.py +306 -58
- sqlspec/adapters/sqlite/driver.py +136 -34
- sqlspec/base.py +413 -9
- sqlspec/extensions/litestar/plugin.py +2 -0
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/METADATA +141 -2
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/RECORD +17 -17
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/WHEEL +0 -0
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/licenses/LICENSE +0 -0
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
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
4
|
from sqlspec.base import (
|
|
5
5
|
AsyncArrowBulkOperationsMixin,
|
|
@@ -11,7 +11,7 @@ from sqlspec.base import (
|
|
|
11
11
|
from sqlspec.typing import ArrowTable, StatementParameterType
|
|
12
12
|
|
|
13
13
|
if TYPE_CHECKING:
|
|
14
|
-
from collections.abc import AsyncGenerator, Generator
|
|
14
|
+
from collections.abc import AsyncGenerator, Generator, Sequence
|
|
15
15
|
|
|
16
16
|
from oracledb import AsyncConnection, AsyncCursor, Connection, Cursor
|
|
17
17
|
|
|
@@ -39,6 +39,29 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
39
39
|
finally:
|
|
40
40
|
cursor.close()
|
|
41
41
|
|
|
42
|
+
# --- Public API Methods --- #
|
|
43
|
+
@overload
|
|
44
|
+
def select(
|
|
45
|
+
self,
|
|
46
|
+
sql: str,
|
|
47
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
48
|
+
/,
|
|
49
|
+
*,
|
|
50
|
+
connection: "Optional[Connection]" = None,
|
|
51
|
+
schema_type: None = None,
|
|
52
|
+
**kwargs: Any,
|
|
53
|
+
) -> "Sequence[dict[str, Any]]": ...
|
|
54
|
+
@overload
|
|
55
|
+
def select(
|
|
56
|
+
self,
|
|
57
|
+
sql: str,
|
|
58
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
59
|
+
/,
|
|
60
|
+
*,
|
|
61
|
+
connection: "Optional[Connection]" = None,
|
|
62
|
+
schema_type: "type[ModelDTOT]",
|
|
63
|
+
**kwargs: Any,
|
|
64
|
+
) -> "Sequence[ModelDTOT]": ...
|
|
42
65
|
def select(
|
|
43
66
|
self,
|
|
44
67
|
sql: str,
|
|
@@ -48,7 +71,7 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
48
71
|
connection: "Optional[Connection]" = None,
|
|
49
72
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
50
73
|
**kwargs: Any,
|
|
51
|
-
) -> "
|
|
74
|
+
) -> "Sequence[Union[ModelDTOT, dict[str, Any]]]":
|
|
52
75
|
"""Fetch data from the database.
|
|
53
76
|
|
|
54
77
|
Args:
|
|
@@ -76,6 +99,28 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
76
99
|
|
|
77
100
|
return [dict(zip(column_names, row)) for row in results] # pyright: ignore
|
|
78
101
|
|
|
102
|
+
@overload
|
|
103
|
+
def select_one(
|
|
104
|
+
self,
|
|
105
|
+
sql: str,
|
|
106
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
107
|
+
/,
|
|
108
|
+
*,
|
|
109
|
+
connection: "Optional[Connection]" = None,
|
|
110
|
+
schema_type: None = None,
|
|
111
|
+
**kwargs: Any,
|
|
112
|
+
) -> "dict[str, Any]": ...
|
|
113
|
+
@overload
|
|
114
|
+
def select_one(
|
|
115
|
+
self,
|
|
116
|
+
sql: str,
|
|
117
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
118
|
+
/,
|
|
119
|
+
*,
|
|
120
|
+
connection: "Optional[Connection]" = None,
|
|
121
|
+
schema_type: "type[ModelDTOT]",
|
|
122
|
+
**kwargs: Any,
|
|
123
|
+
) -> "ModelDTOT": ...
|
|
79
124
|
def select_one(
|
|
80
125
|
self,
|
|
81
126
|
sql: str,
|
|
@@ -114,6 +159,28 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
114
159
|
# Always return dictionaries
|
|
115
160
|
return dict(zip(column_names, result)) # pyright: ignore[reportUnknownArgumentType,reportUnknownVariableType]
|
|
116
161
|
|
|
162
|
+
@overload
|
|
163
|
+
def select_one_or_none(
|
|
164
|
+
self,
|
|
165
|
+
sql: str,
|
|
166
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
167
|
+
/,
|
|
168
|
+
*,
|
|
169
|
+
connection: "Optional[Connection]" = None,
|
|
170
|
+
schema_type: None = None,
|
|
171
|
+
**kwargs: Any,
|
|
172
|
+
) -> "Optional[dict[str, Any]]": ...
|
|
173
|
+
@overload
|
|
174
|
+
def select_one_or_none(
|
|
175
|
+
self,
|
|
176
|
+
sql: str,
|
|
177
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
178
|
+
/,
|
|
179
|
+
*,
|
|
180
|
+
connection: "Optional[Connection]" = None,
|
|
181
|
+
schema_type: "type[ModelDTOT]",
|
|
182
|
+
**kwargs: Any,
|
|
183
|
+
) -> "Optional[ModelDTOT]": ...
|
|
117
184
|
def select_one_or_none(
|
|
118
185
|
self,
|
|
119
186
|
sql: str,
|
|
@@ -147,6 +214,28 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
147
214
|
# Always return dictionaries
|
|
148
215
|
return dict(zip(column_names, result)) # pyright: ignore[reportUnknownArgumentType,reportUnknownVariableType]
|
|
149
216
|
|
|
217
|
+
@overload
|
|
218
|
+
def select_value(
|
|
219
|
+
self,
|
|
220
|
+
sql: str,
|
|
221
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
222
|
+
/,
|
|
223
|
+
*,
|
|
224
|
+
connection: "Optional[Connection]" = None,
|
|
225
|
+
schema_type: None = None,
|
|
226
|
+
**kwargs: Any,
|
|
227
|
+
) -> "Any": ...
|
|
228
|
+
@overload
|
|
229
|
+
def select_value(
|
|
230
|
+
self,
|
|
231
|
+
sql: str,
|
|
232
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
233
|
+
/,
|
|
234
|
+
*,
|
|
235
|
+
connection: "Optional[Connection]" = None,
|
|
236
|
+
schema_type: "type[T]",
|
|
237
|
+
**kwargs: Any,
|
|
238
|
+
) -> "T": ...
|
|
150
239
|
def select_value(
|
|
151
240
|
self,
|
|
152
241
|
sql: str,
|
|
@@ -174,6 +263,28 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
174
263
|
return result[0] # pyright: ignore[reportUnknownArgumentType]
|
|
175
264
|
return schema_type(result[0]) # type: ignore[call-arg]
|
|
176
265
|
|
|
266
|
+
@overload
|
|
267
|
+
def select_value_or_none(
|
|
268
|
+
self,
|
|
269
|
+
sql: str,
|
|
270
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
271
|
+
/,
|
|
272
|
+
*,
|
|
273
|
+
connection: "Optional[Connection]" = None,
|
|
274
|
+
schema_type: None = None,
|
|
275
|
+
**kwargs: Any,
|
|
276
|
+
) -> "Optional[Any]": ...
|
|
277
|
+
@overload
|
|
278
|
+
def select_value_or_none(
|
|
279
|
+
self,
|
|
280
|
+
sql: str,
|
|
281
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
282
|
+
/,
|
|
283
|
+
*,
|
|
284
|
+
connection: "Optional[Connection]" = None,
|
|
285
|
+
schema_type: "type[T]",
|
|
286
|
+
**kwargs: Any,
|
|
287
|
+
) -> "Optional[T]": ...
|
|
177
288
|
def select_value_or_none(
|
|
178
289
|
self,
|
|
179
290
|
sql: str,
|
|
@@ -224,6 +335,28 @@ class OracleSyncDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAda
|
|
|
224
335
|
cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
225
336
|
return cursor.rowcount # pyright: ignore[reportUnknownMemberType]
|
|
226
337
|
|
|
338
|
+
@overload
|
|
339
|
+
def insert_update_delete_returning(
|
|
340
|
+
self,
|
|
341
|
+
sql: str,
|
|
342
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
343
|
+
/,
|
|
344
|
+
*,
|
|
345
|
+
connection: "Optional[Connection]" = None,
|
|
346
|
+
schema_type: None = None,
|
|
347
|
+
**kwargs: Any,
|
|
348
|
+
) -> "dict[str, Any]": ...
|
|
349
|
+
@overload
|
|
350
|
+
def insert_update_delete_returning(
|
|
351
|
+
self,
|
|
352
|
+
sql: str,
|
|
353
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
354
|
+
/,
|
|
355
|
+
*,
|
|
356
|
+
connection: "Optional[Connection]" = None,
|
|
357
|
+
schema_type: "type[ModelDTOT]",
|
|
358
|
+
**kwargs: Any,
|
|
359
|
+
) -> "ModelDTOT": ...
|
|
227
360
|
def insert_update_delete_returning(
|
|
228
361
|
self,
|
|
229
362
|
sql: str,
|
|
@@ -319,6 +452,29 @@ class OracleAsyncDriver(
|
|
|
319
452
|
finally:
|
|
320
453
|
cursor.close()
|
|
321
454
|
|
|
455
|
+
# --- Public API Methods --- #
|
|
456
|
+
@overload
|
|
457
|
+
async def select(
|
|
458
|
+
self,
|
|
459
|
+
sql: str,
|
|
460
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
461
|
+
/,
|
|
462
|
+
*,
|
|
463
|
+
connection: "Optional[AsyncConnection]" = None,
|
|
464
|
+
schema_type: None = None,
|
|
465
|
+
**kwargs: Any,
|
|
466
|
+
) -> "Sequence[dict[str, Any]]": ...
|
|
467
|
+
@overload
|
|
468
|
+
async def select(
|
|
469
|
+
self,
|
|
470
|
+
sql: str,
|
|
471
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
472
|
+
/,
|
|
473
|
+
*,
|
|
474
|
+
connection: "Optional[AsyncConnection]" = None,
|
|
475
|
+
schema_type: "type[ModelDTOT]",
|
|
476
|
+
**kwargs: Any,
|
|
477
|
+
) -> "Sequence[ModelDTOT]": ...
|
|
322
478
|
async def select(
|
|
323
479
|
self,
|
|
324
480
|
sql: str,
|
|
@@ -328,7 +484,7 @@ class OracleAsyncDriver(
|
|
|
328
484
|
connection: "Optional[AsyncConnection]" = None,
|
|
329
485
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
330
486
|
**kwargs: Any,
|
|
331
|
-
) -> "
|
|
487
|
+
) -> "Sequence[Union[ModelDTOT, dict[str, Any]]]":
|
|
332
488
|
"""Fetch data from the database.
|
|
333
489
|
|
|
334
490
|
Returns:
|
|
@@ -350,6 +506,28 @@ class OracleAsyncDriver(
|
|
|
350
506
|
|
|
351
507
|
return [dict(zip(column_names, row)) for row in results] # pyright: ignore
|
|
352
508
|
|
|
509
|
+
@overload
|
|
510
|
+
async def select_one(
|
|
511
|
+
self,
|
|
512
|
+
sql: str,
|
|
513
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
514
|
+
/,
|
|
515
|
+
*,
|
|
516
|
+
connection: "Optional[AsyncConnection]" = None,
|
|
517
|
+
schema_type: None = None,
|
|
518
|
+
**kwargs: Any,
|
|
519
|
+
) -> "dict[str, Any]": ...
|
|
520
|
+
@overload
|
|
521
|
+
async def select_one(
|
|
522
|
+
self,
|
|
523
|
+
sql: str,
|
|
524
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
525
|
+
/,
|
|
526
|
+
*,
|
|
527
|
+
connection: "Optional[AsyncConnection]" = None,
|
|
528
|
+
schema_type: "type[ModelDTOT]",
|
|
529
|
+
**kwargs: Any,
|
|
530
|
+
) -> "ModelDTOT": ...
|
|
353
531
|
async def select_one(
|
|
354
532
|
self,
|
|
355
533
|
sql: str,
|
|
@@ -380,6 +558,28 @@ class OracleAsyncDriver(
|
|
|
380
558
|
# Always return dictionaries
|
|
381
559
|
return dict(zip(column_names, result)) # pyright: ignore[reportUnknownArgumentType,reportUnknownVariableType]
|
|
382
560
|
|
|
561
|
+
@overload
|
|
562
|
+
async def select_one_or_none(
|
|
563
|
+
self,
|
|
564
|
+
sql: str,
|
|
565
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
566
|
+
/,
|
|
567
|
+
*,
|
|
568
|
+
connection: "Optional[AsyncConnection]" = None,
|
|
569
|
+
schema_type: None = None,
|
|
570
|
+
**kwargs: Any,
|
|
571
|
+
) -> "Optional[dict[str, Any]]": ...
|
|
572
|
+
@overload
|
|
573
|
+
async def select_one_or_none(
|
|
574
|
+
self,
|
|
575
|
+
sql: str,
|
|
576
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
577
|
+
/,
|
|
578
|
+
*,
|
|
579
|
+
connection: "Optional[AsyncConnection]" = None,
|
|
580
|
+
schema_type: "type[ModelDTOT]",
|
|
581
|
+
**kwargs: Any,
|
|
582
|
+
) -> "Optional[ModelDTOT]": ...
|
|
383
583
|
async def select_one_or_none(
|
|
384
584
|
self,
|
|
385
585
|
sql: str,
|
|
@@ -413,6 +613,28 @@ class OracleAsyncDriver(
|
|
|
413
613
|
# Always return dictionaries
|
|
414
614
|
return dict(zip(column_names, result)) # pyright: ignore[reportUnknownArgumentType,reportUnknownVariableType]
|
|
415
615
|
|
|
616
|
+
@overload
|
|
617
|
+
async def select_value(
|
|
618
|
+
self,
|
|
619
|
+
sql: str,
|
|
620
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
621
|
+
/,
|
|
622
|
+
*,
|
|
623
|
+
connection: "Optional[AsyncConnection]" = None,
|
|
624
|
+
schema_type: None = None,
|
|
625
|
+
**kwargs: Any,
|
|
626
|
+
) -> "Any": ...
|
|
627
|
+
@overload
|
|
628
|
+
async def select_value(
|
|
629
|
+
self,
|
|
630
|
+
sql: str,
|
|
631
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
632
|
+
/,
|
|
633
|
+
*,
|
|
634
|
+
connection: "Optional[AsyncConnection]" = None,
|
|
635
|
+
schema_type: "type[T]",
|
|
636
|
+
**kwargs: Any,
|
|
637
|
+
) -> "T": ...
|
|
416
638
|
async def select_value(
|
|
417
639
|
self,
|
|
418
640
|
sql: str,
|
|
@@ -440,6 +662,28 @@ class OracleAsyncDriver(
|
|
|
440
662
|
return result[0] # pyright: ignore[reportUnknownArgumentType]
|
|
441
663
|
return schema_type(result[0]) # type: ignore[call-arg]
|
|
442
664
|
|
|
665
|
+
@overload
|
|
666
|
+
async def select_value_or_none(
|
|
667
|
+
self,
|
|
668
|
+
sql: str,
|
|
669
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
670
|
+
/,
|
|
671
|
+
*,
|
|
672
|
+
connection: "Optional[AsyncConnection]" = None,
|
|
673
|
+
schema_type: None = None,
|
|
674
|
+
**kwargs: Any,
|
|
675
|
+
) -> "Optional[Any]": ...
|
|
676
|
+
@overload
|
|
677
|
+
async def select_value_or_none(
|
|
678
|
+
self,
|
|
679
|
+
sql: str,
|
|
680
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
681
|
+
/,
|
|
682
|
+
*,
|
|
683
|
+
connection: "Optional[AsyncConnection]" = None,
|
|
684
|
+
schema_type: "type[T]",
|
|
685
|
+
**kwargs: Any,
|
|
686
|
+
) -> "Optional[T]": ...
|
|
443
687
|
async def select_value_or_none(
|
|
444
688
|
self,
|
|
445
689
|
sql: str,
|
|
@@ -490,6 +734,28 @@ class OracleAsyncDriver(
|
|
|
490
734
|
await cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
491
735
|
return cursor.rowcount # pyright: ignore[reportUnknownMemberType]
|
|
492
736
|
|
|
737
|
+
@overload
|
|
738
|
+
async def insert_update_delete_returning(
|
|
739
|
+
self,
|
|
740
|
+
sql: str,
|
|
741
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
742
|
+
/,
|
|
743
|
+
*,
|
|
744
|
+
connection: "Optional[AsyncConnection]" = None,
|
|
745
|
+
schema_type: None = None,
|
|
746
|
+
**kwargs: Any,
|
|
747
|
+
) -> "dict[str, Any]": ...
|
|
748
|
+
@overload
|
|
749
|
+
async def insert_update_delete_returning(
|
|
750
|
+
self,
|
|
751
|
+
sql: str,
|
|
752
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
753
|
+
/,
|
|
754
|
+
*,
|
|
755
|
+
connection: "Optional[AsyncConnection]" = None,
|
|
756
|
+
schema_type: "type[ModelDTOT]",
|
|
757
|
+
**kwargs: Any,
|
|
758
|
+
) -> "ModelDTOT": ...
|
|
493
759
|
async def insert_update_delete_returning(
|
|
494
760
|
self,
|
|
495
761
|
sql: str,
|
|
@@ -207,25 +207,17 @@ class PsqlpyConfig(AsyncDatabaseConfig[Connection, ConnectionPool, PsqlpyDriver]
|
|
|
207
207
|
def create_connection(self) -> "Awaitable[Connection]":
|
|
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
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import logging
|
|
5
5
|
import re
|
|
6
|
-
from typing import TYPE_CHECKING, Any, Optional, Union, cast
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Optional, Union, cast, overload
|
|
7
7
|
|
|
8
8
|
from psqlpy.exceptions import RustPSQLDriverPyBaseError
|
|
9
9
|
|
|
@@ -12,6 +12,8 @@ from sqlspec.exceptions import SQLParsingError
|
|
|
12
12
|
from sqlspec.statement import PARAM_REGEX, SQLStatement
|
|
13
13
|
|
|
14
14
|
if TYPE_CHECKING:
|
|
15
|
+
from collections.abc import Sequence
|
|
16
|
+
|
|
15
17
|
from psqlpy import Connection, QueryResult
|
|
16
18
|
|
|
17
19
|
from sqlspec.typing import ModelDTOT, StatementParameterType
|
|
@@ -52,6 +54,17 @@ class PsqlpyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
52
54
|
psqlpy uses $1, $2 style parameters natively.
|
|
53
55
|
This method converts '?' (tuple/list) and ':name' (dict) styles to $n.
|
|
54
56
|
It relies on SQLStatement for initial parameter validation and merging.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
sql: The SQL to process.
|
|
60
|
+
parameters: The parameters to process.
|
|
61
|
+
kwargs: Additional keyword arguments.
|
|
62
|
+
|
|
63
|
+
Raises:
|
|
64
|
+
SQLParsingError: If the SQL is invalid.
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
A tuple of the processed SQL and parameters.
|
|
55
68
|
"""
|
|
56
69
|
stmt = SQLStatement(sql=sql, parameters=parameters, dialect=self.dialect, kwargs=kwargs or None)
|
|
57
70
|
sql, parameters = stmt.process()
|
|
@@ -154,6 +167,29 @@ class PsqlpyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
154
167
|
|
|
155
168
|
return sql, ()
|
|
156
169
|
|
|
170
|
+
# --- Public API Methods --- #
|
|
171
|
+
@overload
|
|
172
|
+
async def select(
|
|
173
|
+
self,
|
|
174
|
+
sql: str,
|
|
175
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
176
|
+
/,
|
|
177
|
+
*,
|
|
178
|
+
connection: "Optional[Connection]" = None,
|
|
179
|
+
schema_type: None = None,
|
|
180
|
+
**kwargs: Any,
|
|
181
|
+
) -> "Sequence[dict[str, Any]]": ...
|
|
182
|
+
@overload
|
|
183
|
+
async def select(
|
|
184
|
+
self,
|
|
185
|
+
sql: str,
|
|
186
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
187
|
+
/,
|
|
188
|
+
*,
|
|
189
|
+
connection: "Optional[Connection]" = None,
|
|
190
|
+
schema_type: "type[ModelDTOT]",
|
|
191
|
+
**kwargs: Any,
|
|
192
|
+
) -> "Sequence[ModelDTOT]": ...
|
|
157
193
|
async def select(
|
|
158
194
|
self,
|
|
159
195
|
sql: str,
|
|
@@ -163,7 +199,7 @@ class PsqlpyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
163
199
|
connection: Optional["Connection"] = None,
|
|
164
200
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
165
201
|
**kwargs: Any,
|
|
166
|
-
) -> "
|
|
202
|
+
) -> "Sequence[Union[ModelDTOT, dict[str, Any]]]":
|
|
167
203
|
connection = self._connection(connection)
|
|
168
204
|
sql, parameters = self._process_sql_params(sql, parameters, **kwargs)
|
|
169
205
|
parameters = parameters or [] # psqlpy expects a list/tuple
|
|
@@ -171,9 +207,31 @@ class PsqlpyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
171
207
|
results: QueryResult = await connection.fetch(sql, parameters=parameters)
|
|
172
208
|
|
|
173
209
|
if schema_type is None:
|
|
174
|
-
return cast("list[dict[str, Any]]", results.result())
|
|
210
|
+
return cast("list[dict[str, Any]]", results.result())
|
|
175
211
|
return results.as_class(as_class=schema_type)
|
|
176
212
|
|
|
213
|
+
@overload
|
|
214
|
+
async def select_one(
|
|
215
|
+
self,
|
|
216
|
+
sql: str,
|
|
217
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
218
|
+
/,
|
|
219
|
+
*,
|
|
220
|
+
connection: "Optional[Connection]" = None,
|
|
221
|
+
schema_type: None = None,
|
|
222
|
+
**kwargs: Any,
|
|
223
|
+
) -> "dict[str, Any]": ...
|
|
224
|
+
@overload
|
|
225
|
+
async def select_one(
|
|
226
|
+
self,
|
|
227
|
+
sql: str,
|
|
228
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
229
|
+
/,
|
|
230
|
+
*,
|
|
231
|
+
connection: "Optional[Connection]" = None,
|
|
232
|
+
schema_type: "type[ModelDTOT]",
|
|
233
|
+
**kwargs: Any,
|
|
234
|
+
) -> "ModelDTOT": ...
|
|
177
235
|
async def select_one(
|
|
178
236
|
self,
|
|
179
237
|
sql: str,
|
|
@@ -195,6 +253,28 @@ class PsqlpyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
195
253
|
return cast("dict[str, Any]", result[0]) # type: ignore[index]
|
|
196
254
|
return result.as_class(as_class=schema_type)[0]
|
|
197
255
|
|
|
256
|
+
@overload
|
|
257
|
+
async def select_one_or_none(
|
|
258
|
+
self,
|
|
259
|
+
sql: str,
|
|
260
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
261
|
+
/,
|
|
262
|
+
*,
|
|
263
|
+
connection: "Optional[Connection]" = None,
|
|
264
|
+
schema_type: None = None,
|
|
265
|
+
**kwargs: Any,
|
|
266
|
+
) -> "Optional[dict[str, Any]]": ...
|
|
267
|
+
@overload
|
|
268
|
+
async def select_one_or_none(
|
|
269
|
+
self,
|
|
270
|
+
sql: str,
|
|
271
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
272
|
+
/,
|
|
273
|
+
*,
|
|
274
|
+
connection: "Optional[Connection]" = None,
|
|
275
|
+
schema_type: "type[ModelDTOT]",
|
|
276
|
+
**kwargs: Any,
|
|
277
|
+
) -> "Optional[ModelDTOT]": ...
|
|
198
278
|
async def select_one_or_none(
|
|
199
279
|
self,
|
|
200
280
|
sql: str,
|
|
@@ -220,6 +300,28 @@ class PsqlpyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
220
300
|
return None
|
|
221
301
|
return cast("ModelDTOT", result[0]) # type: ignore[index]
|
|
222
302
|
|
|
303
|
+
@overload
|
|
304
|
+
async def select_value(
|
|
305
|
+
self,
|
|
306
|
+
sql: str,
|
|
307
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
308
|
+
/,
|
|
309
|
+
*,
|
|
310
|
+
connection: "Optional[Connection]" = None,
|
|
311
|
+
schema_type: None = None,
|
|
312
|
+
**kwargs: Any,
|
|
313
|
+
) -> "Any": ...
|
|
314
|
+
@overload
|
|
315
|
+
async def select_value(
|
|
316
|
+
self,
|
|
317
|
+
sql: str,
|
|
318
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
319
|
+
/,
|
|
320
|
+
*,
|
|
321
|
+
connection: "Optional[Connection]" = None,
|
|
322
|
+
schema_type: "type[T]",
|
|
323
|
+
**kwargs: Any,
|
|
324
|
+
) -> "T": ...
|
|
223
325
|
async def select_value(
|
|
224
326
|
self,
|
|
225
327
|
sql: str,
|
|
@@ -240,6 +342,28 @@ class PsqlpyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
240
342
|
return value
|
|
241
343
|
return schema_type(value) # type: ignore[call-arg]
|
|
242
344
|
|
|
345
|
+
@overload
|
|
346
|
+
async def select_value_or_none(
|
|
347
|
+
self,
|
|
348
|
+
sql: str,
|
|
349
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
350
|
+
/,
|
|
351
|
+
*,
|
|
352
|
+
connection: "Optional[Connection]" = None,
|
|
353
|
+
schema_type: None = None,
|
|
354
|
+
**kwargs: Any,
|
|
355
|
+
) -> "Optional[Any]": ...
|
|
356
|
+
@overload
|
|
357
|
+
async def select_value_or_none(
|
|
358
|
+
self,
|
|
359
|
+
sql: str,
|
|
360
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
361
|
+
/,
|
|
362
|
+
*,
|
|
363
|
+
connection: "Optional[Connection]" = None,
|
|
364
|
+
schema_type: "type[T]",
|
|
365
|
+
**kwargs: Any,
|
|
366
|
+
) -> "Optional[T]": ...
|
|
243
367
|
async def select_value_or_none(
|
|
244
368
|
self,
|
|
245
369
|
sql: str,
|
|
@@ -282,6 +406,28 @@ class PsqlpyDriver(AsyncDriverAdapterProtocol["Connection"]):
|
|
|
282
406
|
# if no error was raised
|
|
283
407
|
return 1
|
|
284
408
|
|
|
409
|
+
@overload
|
|
410
|
+
async def insert_update_delete_returning(
|
|
411
|
+
self,
|
|
412
|
+
sql: str,
|
|
413
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
414
|
+
/,
|
|
415
|
+
*,
|
|
416
|
+
connection: "Optional[Connection]" = None,
|
|
417
|
+
schema_type: None = None,
|
|
418
|
+
**kwargs: Any,
|
|
419
|
+
) -> "dict[str, Any]": ...
|
|
420
|
+
@overload
|
|
421
|
+
async def insert_update_delete_returning(
|
|
422
|
+
self,
|
|
423
|
+
sql: str,
|
|
424
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
425
|
+
/,
|
|
426
|
+
*,
|
|
427
|
+
connection: "Optional[Connection]" = None,
|
|
428
|
+
schema_type: "type[ModelDTOT]",
|
|
429
|
+
**kwargs: Any,
|
|
430
|
+
) -> "ModelDTOT": ...
|
|
285
431
|
async def insert_update_delete_returning(
|
|
286
432
|
self,
|
|
287
433
|
sql: str,
|