sqlspec 0.9.1__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 +37 -30
- sqlspec/adapters/aiosqlite/__init__.py +2 -1
- sqlspec/adapters/aiosqlite/config.py +10 -12
- sqlspec/adapters/aiosqlite/driver.py +36 -31
- sqlspec/adapters/asyncmy/__init__.py +2 -1
- sqlspec/adapters/asyncmy/driver.py +34 -31
- sqlspec/adapters/asyncpg/config.py +1 -3
- sqlspec/adapters/asyncpg/driver.py +7 -3
- 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 +38 -30
- 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 +65 -62
- sqlspec/adapters/psqlpy/__init__.py +9 -0
- sqlspec/adapters/psqlpy/config.py +5 -5
- sqlspec/adapters/psqlpy/driver.py +34 -28
- 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 +63 -53
- sqlspec/adapters/sqlite/__init__.py +2 -1
- sqlspec/adapters/sqlite/config.py +12 -11
- sqlspec/adapters/sqlite/driver.py +36 -29
- sqlspec/base.py +1 -66
- sqlspec/exceptions.py +9 -0
- sqlspec/extensions/litestar/config.py +3 -11
- sqlspec/extensions/litestar/handlers.py +2 -1
- sqlspec/extensions/litestar/plugin.py +4 -2
- sqlspec/mixins.py +156 -0
- sqlspec/typing.py +19 -1
- {sqlspec-0.9.1.dist-info → sqlspec-0.10.0.dist-info}/METADATA +8 -3
- sqlspec-0.10.0.dist-info/RECORD +67 -0
- sqlspec-0.9.1.dist-info/RECORD +0 -61
- {sqlspec-0.9.1.dist-info → sqlspec-0.10.0.dist-info}/WHEEL +0 -0
- {sqlspec-0.9.1.dist-info → sqlspec-0.10.0.dist-info}/licenses/LICENSE +0 -0
- {sqlspec-0.9.1.dist-info → sqlspec-0.10.0.dist-info}/licenses/NOTICE +0 -0
|
@@ -2,25 +2,28 @@ import logging
|
|
|
2
2
|
from contextlib import asynccontextmanager, contextmanager
|
|
3
3
|
from typing import TYPE_CHECKING, Any, Optional, Union, cast, overload
|
|
4
4
|
|
|
5
|
+
from psycopg import AsyncConnection, Connection
|
|
5
6
|
from psycopg.rows import dict_row
|
|
6
7
|
|
|
7
|
-
from sqlspec.base import AsyncDriverAdapterProtocol, SyncDriverAdapterProtocol
|
|
8
|
+
from sqlspec.base import AsyncDriverAdapterProtocol, SyncDriverAdapterProtocol
|
|
8
9
|
from sqlspec.exceptions import SQLParsingError
|
|
10
|
+
from sqlspec.mixins import SQLTranslatorMixin
|
|
9
11
|
from sqlspec.statement import PARAM_REGEX, SQLStatement
|
|
10
12
|
|
|
11
13
|
if TYPE_CHECKING:
|
|
12
14
|
from collections.abc import AsyncGenerator, Generator, Sequence
|
|
13
15
|
|
|
14
|
-
from
|
|
15
|
-
|
|
16
|
-
from sqlspec.typing import ModelDTOT, StatementParameterType
|
|
16
|
+
from sqlspec.typing import ModelDTOT, StatementParameterType, T
|
|
17
17
|
|
|
18
18
|
logger = logging.getLogger("sqlspec")
|
|
19
19
|
|
|
20
|
-
__all__ = ("PsycopgAsyncDriver", "PsycopgSyncDriver")
|
|
20
|
+
__all__ = ("PsycopgAsyncConnection", "PsycopgAsyncDriver", "PsycopgSyncConnection", "PsycopgSyncDriver")
|
|
21
|
+
|
|
22
|
+
PsycopgSyncConnection = Connection
|
|
23
|
+
PsycopgAsyncConnection = AsyncConnection
|
|
21
24
|
|
|
22
25
|
|
|
23
|
-
class
|
|
26
|
+
class PsycopgDriverBase:
|
|
24
27
|
dialect: str
|
|
25
28
|
|
|
26
29
|
def _process_sql_params(
|
|
@@ -76,13 +79,17 @@ class PsycopgParameterParser:
|
|
|
76
79
|
return processed_sql, processed_params
|
|
77
80
|
|
|
78
81
|
|
|
79
|
-
class PsycopgSyncDriver(
|
|
82
|
+
class PsycopgSyncDriver(
|
|
83
|
+
PsycopgDriverBase,
|
|
84
|
+
SQLTranslatorMixin["PsycopgSyncConnection"],
|
|
85
|
+
SyncDriverAdapterProtocol["PsycopgSyncConnection"],
|
|
86
|
+
):
|
|
80
87
|
"""Psycopg Sync Driver Adapter."""
|
|
81
88
|
|
|
82
|
-
connection: "
|
|
89
|
+
connection: "PsycopgSyncConnection"
|
|
83
90
|
dialect: str = "postgres"
|
|
84
91
|
|
|
85
|
-
def __init__(self, connection: "
|
|
92
|
+
def __init__(self, connection: "PsycopgSyncConnection") -> None:
|
|
86
93
|
self.connection = connection
|
|
87
94
|
|
|
88
95
|
def _process_sql_params(
|
|
@@ -92,7 +99,6 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
92
99
|
/,
|
|
93
100
|
**kwargs: Any,
|
|
94
101
|
) -> "tuple[str, Optional[Union[tuple[Any, ...], list[Any], dict[str, Any]]]]":
|
|
95
|
-
"""Process SQL and parameters, converting :name -> %(name)s if needed."""
|
|
96
102
|
stmt = SQLStatement(sql=sql, parameters=parameters, dialect=self.dialect, kwargs=kwargs or None)
|
|
97
103
|
processed_sql, processed_params = stmt.process()
|
|
98
104
|
|
|
@@ -139,7 +145,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
139
145
|
|
|
140
146
|
@staticmethod
|
|
141
147
|
@contextmanager
|
|
142
|
-
def _with_cursor(connection: "
|
|
148
|
+
def _with_cursor(connection: "PsycopgSyncConnection") -> "Generator[Any, None, None]":
|
|
143
149
|
cursor = connection.cursor(row_factory=dict_row)
|
|
144
150
|
try:
|
|
145
151
|
yield cursor
|
|
@@ -154,7 +160,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
154
160
|
parameters: "Optional[StatementParameterType]" = None,
|
|
155
161
|
/,
|
|
156
162
|
*,
|
|
157
|
-
connection: "Optional[
|
|
163
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
158
164
|
schema_type: None = None,
|
|
159
165
|
**kwargs: Any,
|
|
160
166
|
) -> "Sequence[dict[str, Any]]": ...
|
|
@@ -165,7 +171,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
165
171
|
parameters: "Optional[StatementParameterType]" = None,
|
|
166
172
|
/,
|
|
167
173
|
*,
|
|
168
|
-
connection: "Optional[
|
|
174
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
169
175
|
schema_type: "type[ModelDTOT]",
|
|
170
176
|
**kwargs: Any,
|
|
171
177
|
) -> "Sequence[ModelDTOT]": ...
|
|
@@ -176,7 +182,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
176
182
|
/,
|
|
177
183
|
*,
|
|
178
184
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
179
|
-
connection: "Optional[
|
|
185
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
180
186
|
**kwargs: Any,
|
|
181
187
|
) -> "Sequence[Union[ModelDTOT, dict[str, Any]]]":
|
|
182
188
|
"""Fetch data from the database.
|
|
@@ -203,7 +209,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
203
209
|
parameters: "Optional[StatementParameterType]" = None,
|
|
204
210
|
/,
|
|
205
211
|
*,
|
|
206
|
-
connection: "Optional[
|
|
212
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
207
213
|
schema_type: None = None,
|
|
208
214
|
**kwargs: Any,
|
|
209
215
|
) -> "dict[str, Any]": ...
|
|
@@ -214,7 +220,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
214
220
|
parameters: "Optional[StatementParameterType]" = None,
|
|
215
221
|
/,
|
|
216
222
|
*,
|
|
217
|
-
connection: "Optional[
|
|
223
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
218
224
|
schema_type: "type[ModelDTOT]",
|
|
219
225
|
**kwargs: Any,
|
|
220
226
|
) -> "ModelDTOT": ...
|
|
@@ -224,7 +230,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
224
230
|
parameters: "Optional[StatementParameterType]" = None,
|
|
225
231
|
/,
|
|
226
232
|
*,
|
|
227
|
-
connection: "Optional[
|
|
233
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
228
234
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
229
235
|
**kwargs: Any,
|
|
230
236
|
) -> "Union[ModelDTOT, dict[str, Any]]":
|
|
@@ -250,7 +256,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
250
256
|
parameters: "Optional[StatementParameterType]" = None,
|
|
251
257
|
/,
|
|
252
258
|
*,
|
|
253
|
-
connection: "Optional[
|
|
259
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
254
260
|
schema_type: None = None,
|
|
255
261
|
**kwargs: Any,
|
|
256
262
|
) -> "Optional[dict[str, Any]]": ...
|
|
@@ -261,7 +267,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
261
267
|
parameters: "Optional[StatementParameterType]" = None,
|
|
262
268
|
/,
|
|
263
269
|
*,
|
|
264
|
-
connection: "Optional[
|
|
270
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
265
271
|
schema_type: "type[ModelDTOT]",
|
|
266
272
|
**kwargs: Any,
|
|
267
273
|
) -> "Optional[ModelDTOT]": ...
|
|
@@ -271,7 +277,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
271
277
|
parameters: "Optional[StatementParameterType]" = None,
|
|
272
278
|
/,
|
|
273
279
|
*,
|
|
274
|
-
connection: "Optional[
|
|
280
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
275
281
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
276
282
|
**kwargs: Any,
|
|
277
283
|
) -> "Optional[Union[ModelDTOT, dict[str, Any]]]":
|
|
@@ -298,7 +304,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
298
304
|
parameters: "Optional[StatementParameterType]" = None,
|
|
299
305
|
/,
|
|
300
306
|
*,
|
|
301
|
-
connection: "Optional[
|
|
307
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
302
308
|
schema_type: None = None,
|
|
303
309
|
**kwargs: Any,
|
|
304
310
|
) -> "Any": ...
|
|
@@ -309,7 +315,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
309
315
|
parameters: "Optional[StatementParameterType]" = None,
|
|
310
316
|
/,
|
|
311
317
|
*,
|
|
312
|
-
connection: "Optional[
|
|
318
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
313
319
|
schema_type: "type[T]",
|
|
314
320
|
**kwargs: Any,
|
|
315
321
|
) -> "T": ...
|
|
@@ -319,7 +325,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
319
325
|
parameters: "Optional[StatementParameterType]" = None,
|
|
320
326
|
/,
|
|
321
327
|
*,
|
|
322
|
-
connection: "Optional[
|
|
328
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
323
329
|
schema_type: "Optional[type[T]]" = None,
|
|
324
330
|
**kwargs: Any,
|
|
325
331
|
) -> "Union[T, Any]":
|
|
@@ -347,7 +353,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
347
353
|
parameters: "Optional[StatementParameterType]" = None,
|
|
348
354
|
/,
|
|
349
355
|
*,
|
|
350
|
-
connection: "Optional[
|
|
356
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
351
357
|
schema_type: None = None,
|
|
352
358
|
**kwargs: Any,
|
|
353
359
|
) -> "Optional[Any]": ...
|
|
@@ -358,7 +364,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
358
364
|
parameters: "Optional[StatementParameterType]" = None,
|
|
359
365
|
/,
|
|
360
366
|
*,
|
|
361
|
-
connection: "Optional[
|
|
367
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
362
368
|
schema_type: "type[T]",
|
|
363
369
|
**kwargs: Any,
|
|
364
370
|
) -> "Optional[T]": ...
|
|
@@ -368,7 +374,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
368
374
|
parameters: "Optional[StatementParameterType]" = None,
|
|
369
375
|
/,
|
|
370
376
|
*,
|
|
371
|
-
connection: "Optional[
|
|
377
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
372
378
|
schema_type: "Optional[type[T]]" = None,
|
|
373
379
|
**kwargs: Any,
|
|
374
380
|
) -> "Optional[Union[T, Any]]":
|
|
@@ -397,7 +403,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
397
403
|
parameters: "Optional[StatementParameterType]" = None,
|
|
398
404
|
/,
|
|
399
405
|
*,
|
|
400
|
-
connection: "Optional[
|
|
406
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
401
407
|
**kwargs: Any,
|
|
402
408
|
) -> int:
|
|
403
409
|
"""Execute an INSERT, UPDATE, or DELETE query and return the number of affected rows.
|
|
@@ -418,7 +424,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
418
424
|
parameters: "Optional[StatementParameterType]" = None,
|
|
419
425
|
/,
|
|
420
426
|
*,
|
|
421
|
-
connection: "Optional[
|
|
427
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
422
428
|
schema_type: None = None,
|
|
423
429
|
**kwargs: Any,
|
|
424
430
|
) -> "dict[str, Any]": ...
|
|
@@ -429,7 +435,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
429
435
|
parameters: "Optional[StatementParameterType]" = None,
|
|
430
436
|
/,
|
|
431
437
|
*,
|
|
432
|
-
connection: "Optional[
|
|
438
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
433
439
|
schema_type: "type[ModelDTOT]",
|
|
434
440
|
**kwargs: Any,
|
|
435
441
|
) -> "ModelDTOT": ...
|
|
@@ -439,7 +445,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
439
445
|
parameters: "Optional[StatementParameterType]" = None,
|
|
440
446
|
/,
|
|
441
447
|
*,
|
|
442
|
-
connection: "Optional[
|
|
448
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
443
449
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
444
450
|
**kwargs: Any,
|
|
445
451
|
) -> "Optional[Union[dict[str, Any], ModelDTOT]]":
|
|
@@ -467,7 +473,7 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
467
473
|
parameters: "Optional[StatementParameterType]" = None,
|
|
468
474
|
/,
|
|
469
475
|
*,
|
|
470
|
-
connection: "Optional[
|
|
476
|
+
connection: "Optional[PsycopgSyncConnection]" = None,
|
|
471
477
|
**kwargs: Any,
|
|
472
478
|
) -> str:
|
|
473
479
|
"""Execute a script.
|
|
@@ -482,18 +488,22 @@ class PsycopgSyncDriver(PsycopgParameterParser, SyncDriverAdapterProtocol["Conne
|
|
|
482
488
|
return str(cursor.statusmessage) if cursor.statusmessage is not None else "DONE"
|
|
483
489
|
|
|
484
490
|
|
|
485
|
-
class PsycopgAsyncDriver(
|
|
491
|
+
class PsycopgAsyncDriver(
|
|
492
|
+
PsycopgDriverBase,
|
|
493
|
+
SQLTranslatorMixin["PsycopgAsyncConnection"],
|
|
494
|
+
AsyncDriverAdapterProtocol["PsycopgAsyncConnection"],
|
|
495
|
+
):
|
|
486
496
|
"""Psycopg Async Driver Adapter."""
|
|
487
497
|
|
|
488
|
-
connection: "
|
|
498
|
+
connection: "PsycopgAsyncConnection"
|
|
489
499
|
dialect: str = "postgres"
|
|
490
500
|
|
|
491
|
-
def __init__(self, connection: "
|
|
501
|
+
def __init__(self, connection: "PsycopgAsyncConnection") -> None:
|
|
492
502
|
self.connection = connection
|
|
493
503
|
|
|
494
504
|
@staticmethod
|
|
495
505
|
@asynccontextmanager
|
|
496
|
-
async def _with_cursor(connection: "
|
|
506
|
+
async def _with_cursor(connection: "PsycopgAsyncConnection") -> "AsyncGenerator[Any, None]":
|
|
497
507
|
cursor = connection.cursor(row_factory=dict_row)
|
|
498
508
|
try:
|
|
499
509
|
yield cursor
|
|
@@ -508,7 +518,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
508
518
|
parameters: "Optional[StatementParameterType]" = None,
|
|
509
519
|
/,
|
|
510
520
|
*,
|
|
511
|
-
connection: "Optional[
|
|
521
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
512
522
|
schema_type: None = None,
|
|
513
523
|
**kwargs: Any,
|
|
514
524
|
) -> "Sequence[dict[str, Any]]": ...
|
|
@@ -519,7 +529,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
519
529
|
parameters: "Optional[StatementParameterType]" = None,
|
|
520
530
|
/,
|
|
521
531
|
*,
|
|
522
|
-
connection: "Optional[
|
|
532
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
523
533
|
schema_type: "type[ModelDTOT]",
|
|
524
534
|
**kwargs: Any,
|
|
525
535
|
) -> "Sequence[ModelDTOT]": ...
|
|
@@ -529,7 +539,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
529
539
|
parameters: "Optional[StatementParameterType]" = None,
|
|
530
540
|
/,
|
|
531
541
|
*,
|
|
532
|
-
connection: "Optional[
|
|
542
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
533
543
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
534
544
|
**kwargs: Any,
|
|
535
545
|
) -> "Sequence[Union[ModelDTOT, dict[str, Any]]]":
|
|
@@ -558,7 +568,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
558
568
|
parameters: "Optional[StatementParameterType]" = None,
|
|
559
569
|
/,
|
|
560
570
|
*,
|
|
561
|
-
connection: "Optional[
|
|
571
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
562
572
|
schema_type: None = None,
|
|
563
573
|
**kwargs: Any,
|
|
564
574
|
) -> "dict[str, Any]": ...
|
|
@@ -569,7 +579,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
569
579
|
parameters: "Optional[StatementParameterType]" = None,
|
|
570
580
|
/,
|
|
571
581
|
*,
|
|
572
|
-
connection: "Optional[
|
|
582
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
573
583
|
schema_type: "type[ModelDTOT]",
|
|
574
584
|
**kwargs: Any,
|
|
575
585
|
) -> "ModelDTOT": ...
|
|
@@ -579,7 +589,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
579
589
|
parameters: "Optional[StatementParameterType]" = None,
|
|
580
590
|
/,
|
|
581
591
|
*,
|
|
582
|
-
connection: "Optional[
|
|
592
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
583
593
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
584
594
|
**kwargs: Any,
|
|
585
595
|
) -> "Union[ModelDTOT, dict[str, Any]]":
|
|
@@ -606,7 +616,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
606
616
|
parameters: "Optional[StatementParameterType]" = None,
|
|
607
617
|
/,
|
|
608
618
|
*,
|
|
609
|
-
connection: "Optional[
|
|
619
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
610
620
|
schema_type: None = None,
|
|
611
621
|
**kwargs: Any,
|
|
612
622
|
) -> "Optional[dict[str, Any]]": ...
|
|
@@ -617,7 +627,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
617
627
|
parameters: "Optional[StatementParameterType]" = None,
|
|
618
628
|
/,
|
|
619
629
|
*,
|
|
620
|
-
connection: "Optional[
|
|
630
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
621
631
|
schema_type: "type[ModelDTOT]",
|
|
622
632
|
**kwargs: Any,
|
|
623
633
|
) -> "Optional[ModelDTOT]": ...
|
|
@@ -628,7 +638,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
628
638
|
/,
|
|
629
639
|
*,
|
|
630
640
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
631
|
-
connection: "Optional[
|
|
641
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
632
642
|
**kwargs: Any,
|
|
633
643
|
) -> "Optional[Union[ModelDTOT, dict[str, Any]]]":
|
|
634
644
|
"""Fetch one row from the database.
|
|
@@ -655,7 +665,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
655
665
|
parameters: "Optional[StatementParameterType]" = None,
|
|
656
666
|
/,
|
|
657
667
|
*,
|
|
658
|
-
connection: "Optional[
|
|
668
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
659
669
|
schema_type: None = None,
|
|
660
670
|
**kwargs: Any,
|
|
661
671
|
) -> "Any": ...
|
|
@@ -666,7 +676,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
666
676
|
parameters: "Optional[StatementParameterType]" = None,
|
|
667
677
|
/,
|
|
668
678
|
*,
|
|
669
|
-
connection: "Optional[
|
|
679
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
670
680
|
schema_type: "type[T]",
|
|
671
681
|
**kwargs: Any,
|
|
672
682
|
) -> "T": ...
|
|
@@ -676,7 +686,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
676
686
|
parameters: "Optional[StatementParameterType]" = None,
|
|
677
687
|
/,
|
|
678
688
|
*,
|
|
679
|
-
connection: "Optional[
|
|
689
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
680
690
|
schema_type: "Optional[type[T]]" = None,
|
|
681
691
|
**kwargs: Any,
|
|
682
692
|
) -> "Union[T, Any]":
|
|
@@ -704,7 +714,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
704
714
|
parameters: "Optional[StatementParameterType]" = None,
|
|
705
715
|
/,
|
|
706
716
|
*,
|
|
707
|
-
connection: "Optional[
|
|
717
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
708
718
|
schema_type: "Optional[type[T]]" = None,
|
|
709
719
|
**kwargs: Any,
|
|
710
720
|
) -> "Optional[Union[T, Any]]":
|
|
@@ -734,7 +744,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
734
744
|
parameters: "Optional[StatementParameterType]" = None,
|
|
735
745
|
/,
|
|
736
746
|
*,
|
|
737
|
-
connection: "Optional[
|
|
747
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
738
748
|
**kwargs: Any,
|
|
739
749
|
) -> int:
|
|
740
750
|
"""Execute an INSERT, UPDATE, or DELETE query and return the number of affected rows.
|
|
@@ -760,7 +770,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
760
770
|
parameters: "Optional[StatementParameterType]" = None,
|
|
761
771
|
/,
|
|
762
772
|
*,
|
|
763
|
-
connection: "Optional[
|
|
773
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
764
774
|
schema_type: None = None,
|
|
765
775
|
**kwargs: Any,
|
|
766
776
|
) -> "dict[str, Any]": ...
|
|
@@ -771,7 +781,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
771
781
|
parameters: "Optional[StatementParameterType]" = None,
|
|
772
782
|
/,
|
|
773
783
|
*,
|
|
774
|
-
connection: "Optional[
|
|
784
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
775
785
|
schema_type: "type[ModelDTOT]",
|
|
776
786
|
**kwargs: Any,
|
|
777
787
|
) -> "ModelDTOT": ...
|
|
@@ -781,7 +791,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
781
791
|
parameters: "Optional[StatementParameterType]" = None,
|
|
782
792
|
/,
|
|
783
793
|
*,
|
|
784
|
-
connection: "Optional[
|
|
794
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
785
795
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
786
796
|
**kwargs: Any,
|
|
787
797
|
) -> "Optional[Union[dict[str, Any], ModelDTOT]]":
|
|
@@ -810,7 +820,7 @@ class PsycopgAsyncDriver(PsycopgParameterParser, AsyncDriverAdapterProtocol["Asy
|
|
|
810
820
|
parameters: "Optional[StatementParameterType]" = None,
|
|
811
821
|
/,
|
|
812
822
|
*,
|
|
813
|
-
connection: "Optional[
|
|
823
|
+
connection: "Optional[PsycopgAsyncConnection]" = None,
|
|
814
824
|
**kwargs: Any,
|
|
815
825
|
) -> str:
|
|
816
826
|
"""Execute a script.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
from sqlspec.adapters.sqlite.config import SqliteConfig
|
|
2
|
-
from sqlspec.adapters.sqlite.driver import SqliteDriver
|
|
2
|
+
from sqlspec.adapters.sqlite.driver import SqliteConnection, SqliteDriver
|
|
3
3
|
|
|
4
4
|
__all__ = (
|
|
5
5
|
"SqliteConfig",
|
|
6
|
+
"SqliteConnection",
|
|
6
7
|
"SqliteDriver",
|
|
7
8
|
)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import sqlite3
|
|
1
2
|
from contextlib import contextmanager
|
|
2
3
|
from dataclasses import dataclass, field
|
|
3
|
-
from sqlite3 import Connection
|
|
4
4
|
from typing import TYPE_CHECKING, Any, Literal, Optional, Union
|
|
5
5
|
|
|
6
|
-
from sqlspec.adapters.sqlite.driver import SqliteDriver
|
|
6
|
+
from sqlspec.adapters.sqlite.driver import SqliteConnection, SqliteDriver
|
|
7
7
|
from sqlspec.base import NoPoolSyncConfig
|
|
8
8
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
9
9
|
from sqlspec.typing import Empty, EmptyType, dataclass_to_dict
|
|
@@ -16,7 +16,7 @@ __all__ = ("SqliteConfig",)
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
@dataclass
|
|
19
|
-
class SqliteConfig(NoPoolSyncConfig["
|
|
19
|
+
class SqliteConfig(NoPoolSyncConfig["SqliteConnection", "SqliteDriver"]):
|
|
20
20
|
"""Configuration for SQLite database connections.
|
|
21
21
|
|
|
22
22
|
This class provides configuration options for SQLite database connections, wrapping all parameters
|
|
@@ -40,7 +40,7 @@ class SqliteConfig(NoPoolSyncConfig["Connection", "SqliteDriver"]):
|
|
|
40
40
|
check_same_thread: "Union[bool, EmptyType]" = Empty
|
|
41
41
|
"""If True (default), ProgrammingError is raised if the database connection is used by a thread other than the one that created it. If False, the connection may be shared across multiple threads."""
|
|
42
42
|
|
|
43
|
-
factory: "Union[type[
|
|
43
|
+
factory: "Union[type[SqliteConnection], EmptyType]" = Empty
|
|
44
44
|
"""A custom Connection class factory. If given, must be a callable that returns a Connection instance."""
|
|
45
45
|
|
|
46
46
|
cached_statements: "Union[int, EmptyType]" = Empty
|
|
@@ -50,7 +50,7 @@ class SqliteConfig(NoPoolSyncConfig["Connection", "SqliteDriver"]):
|
|
|
50
50
|
"""If set to True, database is interpreted as a URI with supported options."""
|
|
51
51
|
driver_type: "type[SqliteDriver]" = field(init=False, default_factory=lambda: SqliteDriver)
|
|
52
52
|
"""Type of the driver object"""
|
|
53
|
-
connection_type: "type[
|
|
53
|
+
connection_type: "type[SqliteConnection]" = field(init=False, default_factory=lambda: SqliteConnection)
|
|
54
54
|
"""Type of the connection object"""
|
|
55
55
|
|
|
56
56
|
@property
|
|
@@ -61,10 +61,13 @@ class SqliteConfig(NoPoolSyncConfig["Connection", "SqliteDriver"]):
|
|
|
61
61
|
A string keyed dict of config kwargs for the sqlite3.connect() function.
|
|
62
62
|
"""
|
|
63
63
|
return dataclass_to_dict(
|
|
64
|
-
self,
|
|
64
|
+
self,
|
|
65
|
+
exclude_empty=True,
|
|
66
|
+
convert_nested=False,
|
|
67
|
+
exclude={"pool_instance", "driver_type", "connection_type"},
|
|
65
68
|
)
|
|
66
69
|
|
|
67
|
-
def create_connection(self) -> "
|
|
70
|
+
def create_connection(self) -> "SqliteConnection":
|
|
68
71
|
"""Create and return a new database connection.
|
|
69
72
|
|
|
70
73
|
Returns:
|
|
@@ -73,8 +76,6 @@ class SqliteConfig(NoPoolSyncConfig["Connection", "SqliteDriver"]):
|
|
|
73
76
|
Raises:
|
|
74
77
|
ImproperConfigurationError: If the connection could not be established.
|
|
75
78
|
"""
|
|
76
|
-
import sqlite3
|
|
77
|
-
|
|
78
79
|
try:
|
|
79
80
|
return sqlite3.connect(**self.connection_config_dict) # type: ignore[no-any-return,unused-ignore]
|
|
80
81
|
except Exception as e:
|
|
@@ -82,7 +83,7 @@ class SqliteConfig(NoPoolSyncConfig["Connection", "SqliteDriver"]):
|
|
|
82
83
|
raise ImproperConfigurationError(msg) from e
|
|
83
84
|
|
|
84
85
|
@contextmanager
|
|
85
|
-
def provide_connection(self, *args: "Any", **kwargs: "Any") -> "Generator[
|
|
86
|
+
def provide_connection(self, *args: "Any", **kwargs: "Any") -> "Generator[SqliteConnection, None, None]":
|
|
86
87
|
"""Create and provide a database connection.
|
|
87
88
|
|
|
88
89
|
Yields:
|
|
@@ -100,7 +101,7 @@ class SqliteConfig(NoPoolSyncConfig["Connection", "SqliteDriver"]):
|
|
|
100
101
|
"""Create and provide a database connection.
|
|
101
102
|
|
|
102
103
|
Yields:
|
|
103
|
-
A
|
|
104
|
+
A SQLite driver instance.
|
|
104
105
|
|
|
105
106
|
|
|
106
107
|
"""
|