sqlspec 0.9.1__py3-none-any.whl → 0.10.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.

Files changed (48) hide show
  1. sqlspec/__init__.py +2 -1
  2. sqlspec/_typing.py +24 -32
  3. sqlspec/adapters/adbc/__init__.py +2 -1
  4. sqlspec/adapters/adbc/config.py +7 -13
  5. sqlspec/adapters/adbc/driver.py +37 -30
  6. sqlspec/adapters/aiosqlite/__init__.py +2 -1
  7. sqlspec/adapters/aiosqlite/config.py +10 -12
  8. sqlspec/adapters/aiosqlite/driver.py +36 -31
  9. sqlspec/adapters/asyncmy/__init__.py +2 -1
  10. sqlspec/adapters/asyncmy/driver.py +34 -31
  11. sqlspec/adapters/asyncpg/config.py +1 -3
  12. sqlspec/adapters/asyncpg/driver.py +7 -3
  13. sqlspec/adapters/bigquery/__init__.py +4 -0
  14. sqlspec/adapters/bigquery/config/__init__.py +3 -0
  15. sqlspec/adapters/bigquery/config/_common.py +40 -0
  16. sqlspec/adapters/bigquery/config/_sync.py +87 -0
  17. sqlspec/adapters/bigquery/driver.py +701 -0
  18. sqlspec/adapters/duckdb/__init__.py +2 -1
  19. sqlspec/adapters/duckdb/config.py +17 -18
  20. sqlspec/adapters/duckdb/driver.py +38 -30
  21. sqlspec/adapters/oracledb/__init__.py +8 -1
  22. sqlspec/adapters/oracledb/config/_asyncio.py +7 -8
  23. sqlspec/adapters/oracledb/config/_sync.py +6 -7
  24. sqlspec/adapters/oracledb/driver.py +65 -62
  25. sqlspec/adapters/psqlpy/__init__.py +9 -0
  26. sqlspec/adapters/psqlpy/config.py +5 -5
  27. sqlspec/adapters/psqlpy/driver.py +34 -28
  28. sqlspec/adapters/psycopg/__init__.py +8 -1
  29. sqlspec/adapters/psycopg/config/__init__.py +10 -0
  30. sqlspec/adapters/psycopg/config/_async.py +6 -7
  31. sqlspec/adapters/psycopg/config/_sync.py +7 -8
  32. sqlspec/adapters/psycopg/driver.py +63 -53
  33. sqlspec/adapters/sqlite/__init__.py +2 -1
  34. sqlspec/adapters/sqlite/config.py +12 -11
  35. sqlspec/adapters/sqlite/driver.py +36 -29
  36. sqlspec/base.py +1 -66
  37. sqlspec/exceptions.py +9 -0
  38. sqlspec/extensions/litestar/config.py +3 -11
  39. sqlspec/extensions/litestar/handlers.py +2 -1
  40. sqlspec/extensions/litestar/plugin.py +4 -2
  41. sqlspec/mixins.py +156 -0
  42. sqlspec/typing.py +19 -1
  43. {sqlspec-0.9.1.dist-info → sqlspec-0.10.1.dist-info}/METADATA +8 -3
  44. sqlspec-0.10.1.dist-info/RECORD +67 -0
  45. sqlspec-0.9.1.dist-info/RECORD +0 -61
  46. {sqlspec-0.9.1.dist-info → sqlspec-0.10.1.dist-info}/WHEEL +0 -0
  47. {sqlspec-0.9.1.dist-info → sqlspec-0.10.1.dist-info}/licenses/LICENSE +0 -0
  48. {sqlspec-0.9.1.dist-info → sqlspec-0.10.1.dist-info}/licenses/NOTICE +0 -0
@@ -1,33 +1,38 @@
1
1
  from contextlib import asynccontextmanager
2
2
  from typing import TYPE_CHECKING, Any, Optional, Union, cast, overload
3
3
 
4
- from sqlspec.base import AsyncDriverAdapterProtocol, T
4
+ import aiosqlite
5
+
6
+ from sqlspec.base import AsyncDriverAdapterProtocol
7
+ from sqlspec.mixins import SQLTranslatorMixin
5
8
 
6
9
  if TYPE_CHECKING:
7
10
  from collections.abc import AsyncGenerator, Sequence
8
11
 
9
- from aiosqlite import Connection, Cursor
10
-
11
- from sqlspec.typing import ModelDTOT, StatementParameterType
12
+ from sqlspec.typing import ModelDTOT, StatementParameterType, T
12
13
 
13
- __all__ = ("AiosqliteDriver",)
14
+ __all__ = ("AiosqliteConnection", "AiosqliteDriver")
15
+ AiosqliteConnection = aiosqlite.Connection
14
16
 
15
17
 
16
- class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
18
+ class AiosqliteDriver(
19
+ SQLTranslatorMixin["AiosqliteConnection"],
20
+ AsyncDriverAdapterProtocol["AiosqliteConnection"],
21
+ ):
17
22
  """SQLite Async Driver Adapter."""
18
23
 
19
- connection: "Connection"
24
+ connection: "AiosqliteConnection"
20
25
  dialect: str = "sqlite"
21
26
 
22
- def __init__(self, connection: "Connection") -> None:
27
+ def __init__(self, connection: "AiosqliteConnection") -> None:
23
28
  self.connection = connection
24
29
 
25
30
  @staticmethod
26
- async def _cursor(connection: "Connection", *args: Any, **kwargs: Any) -> "Cursor":
31
+ async def _cursor(connection: "AiosqliteConnection", *args: Any, **kwargs: Any) -> "aiosqlite.Cursor":
27
32
  return await connection.cursor(*args, **kwargs)
28
33
 
29
34
  @asynccontextmanager
30
- async def _with_cursor(self, connection: "Connection") -> "AsyncGenerator[Cursor, None]":
35
+ async def _with_cursor(self, connection: "AiosqliteConnection") -> "AsyncGenerator[aiosqlite.Cursor, None]":
31
36
  cursor = await self._cursor(connection)
32
37
  try:
33
38
  yield cursor
@@ -42,7 +47,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
42
47
  parameters: "Optional[StatementParameterType]" = None,
43
48
  /,
44
49
  *,
45
- connection: "Optional[Connection]" = None,
50
+ connection: "Optional[AiosqliteConnection]" = None,
46
51
  schema_type: None = None,
47
52
  **kwargs: Any,
48
53
  ) -> "Sequence[dict[str, Any]]": ...
@@ -53,7 +58,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
53
58
  parameters: "Optional[StatementParameterType]" = None,
54
59
  /,
55
60
  *,
56
- connection: "Optional[Connection]" = None,
61
+ connection: "Optional[AiosqliteConnection]" = None,
57
62
  schema_type: "type[ModelDTOT]",
58
63
  **kwargs: Any,
59
64
  ) -> "Sequence[ModelDTOT]": ...
@@ -63,7 +68,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
63
68
  parameters: Optional["StatementParameterType"] = None,
64
69
  /,
65
70
  *,
66
- connection: Optional["Connection"] = None,
71
+ connection: Optional["AiosqliteConnection"] = None,
67
72
  schema_type: "Optional[type[ModelDTOT]]" = None,
68
73
  **kwargs: Any,
69
74
  ) -> "Sequence[Union[ModelDTOT, dict[str, Any]]]":
@@ -91,7 +96,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
91
96
  parameters: "Optional[StatementParameterType]" = None,
92
97
  /,
93
98
  *,
94
- connection: "Optional[Connection]" = None,
99
+ connection: "Optional[AiosqliteConnection]" = None,
95
100
  schema_type: None = None,
96
101
  **kwargs: Any,
97
102
  ) -> "dict[str, Any]": ...
@@ -102,7 +107,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
102
107
  parameters: "Optional[StatementParameterType]" = None,
103
108
  /,
104
109
  *,
105
- connection: "Optional[Connection]" = None,
110
+ connection: "Optional[AiosqliteConnection]" = None,
106
111
  schema_type: "type[ModelDTOT]",
107
112
  **kwargs: Any,
108
113
  ) -> "ModelDTOT": ...
@@ -112,7 +117,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
112
117
  parameters: Optional["StatementParameterType"] = None,
113
118
  /,
114
119
  *,
115
- connection: Optional["Connection"] = None,
120
+ connection: Optional["AiosqliteConnection"] = None,
116
121
  schema_type: "Optional[type[ModelDTOT]]" = None,
117
122
  **kwargs: Any,
118
123
  ) -> "Union[ModelDTOT, dict[str, Any]]":
@@ -139,7 +144,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
139
144
  parameters: "Optional[StatementParameterType]" = None,
140
145
  /,
141
146
  *,
142
- connection: "Optional[Connection]" = None,
147
+ connection: "Optional[AiosqliteConnection]" = None,
143
148
  schema_type: None = None,
144
149
  **kwargs: Any,
145
150
  ) -> "Optional[dict[str, Any]]": ...
@@ -150,7 +155,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
150
155
  parameters: "Optional[StatementParameterType]" = None,
151
156
  /,
152
157
  *,
153
- connection: "Optional[Connection]" = None,
158
+ connection: "Optional[AiosqliteConnection]" = None,
154
159
  schema_type: "type[ModelDTOT]",
155
160
  **kwargs: Any,
156
161
  ) -> "Optional[ModelDTOT]": ...
@@ -160,7 +165,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
160
165
  parameters: Optional["StatementParameterType"] = None,
161
166
  /,
162
167
  *,
163
- connection: Optional["Connection"] = None,
168
+ connection: Optional["AiosqliteConnection"] = None,
164
169
  schema_type: "Optional[type[ModelDTOT]]" = None,
165
170
  **kwargs: Any,
166
171
  ) -> "Optional[Union[ModelDTOT, dict[str, Any]]]":
@@ -188,7 +193,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
188
193
  parameters: "Optional[StatementParameterType]" = None,
189
194
  /,
190
195
  *,
191
- connection: "Optional[Connection]" = None,
196
+ connection: "Optional[AiosqliteConnection]" = None,
192
197
  schema_type: None = None,
193
198
  **kwargs: Any,
194
199
  ) -> "Any": ...
@@ -199,7 +204,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
199
204
  parameters: "Optional[StatementParameterType]" = None,
200
205
  /,
201
206
  *,
202
- connection: "Optional[Connection]" = None,
207
+ connection: "Optional[AiosqliteConnection]" = None,
203
208
  schema_type: "type[T]",
204
209
  **kwargs: Any,
205
210
  ) -> "T": ...
@@ -209,7 +214,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
209
214
  parameters: "Optional[StatementParameterType]" = None,
210
215
  /,
211
216
  *,
212
- connection: "Optional[Connection]" = None,
217
+ connection: "Optional[AiosqliteConnection]" = None,
213
218
  schema_type: "Optional[type[T]]" = None,
214
219
  **kwargs: Any,
215
220
  ) -> "Union[T, Any]":
@@ -235,7 +240,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
235
240
  parameters: "Optional[StatementParameterType]" = None,
236
241
  /,
237
242
  *,
238
- connection: "Optional[Connection]" = None,
243
+ connection: "Optional[AiosqliteConnection]" = None,
239
244
  schema_type: None = None,
240
245
  **kwargs: Any,
241
246
  ) -> "Optional[Any]": ...
@@ -246,7 +251,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
246
251
  parameters: "Optional[StatementParameterType]" = None,
247
252
  /,
248
253
  *,
249
- connection: "Optional[Connection]" = None,
254
+ connection: "Optional[AiosqliteConnection]" = None,
250
255
  schema_type: "type[T]",
251
256
  **kwargs: Any,
252
257
  ) -> "Optional[T]": ...
@@ -256,7 +261,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
256
261
  parameters: "Optional[StatementParameterType]" = None,
257
262
  /,
258
263
  *,
259
- connection: "Optional[Connection]" = None,
264
+ connection: "Optional[AiosqliteConnection]" = None,
260
265
  schema_type: "Optional[type[T]]" = None,
261
266
  **kwargs: Any,
262
267
  ) -> "Optional[Union[T, Any]]":
@@ -282,7 +287,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
282
287
  parameters: Optional["StatementParameterType"] = None,
283
288
  /,
284
289
  *,
285
- connection: Optional["Connection"] = None,
290
+ connection: Optional["AiosqliteConnection"] = None,
286
291
  **kwargs: Any,
287
292
  ) -> int:
288
293
  """Insert, update, or delete data from the database.
@@ -304,7 +309,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
304
309
  parameters: "Optional[StatementParameterType]" = None,
305
310
  /,
306
311
  *,
307
- connection: "Optional[Connection]" = None,
312
+ connection: "Optional[AiosqliteConnection]" = None,
308
313
  schema_type: None = None,
309
314
  **kwargs: Any,
310
315
  ) -> "dict[str, Any]": ...
@@ -315,7 +320,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
315
320
  parameters: "Optional[StatementParameterType]" = None,
316
321
  /,
317
322
  *,
318
- connection: "Optional[Connection]" = None,
323
+ connection: "Optional[AiosqliteConnection]" = None,
319
324
  schema_type: "type[ModelDTOT]",
320
325
  **kwargs: Any,
321
326
  ) -> "ModelDTOT": ...
@@ -325,7 +330,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
325
330
  parameters: Optional["StatementParameterType"] = None,
326
331
  /,
327
332
  *,
328
- connection: Optional["Connection"] = None,
333
+ connection: Optional["AiosqliteConnection"] = None,
329
334
  schema_type: "Optional[type[ModelDTOT]]" = None,
330
335
  **kwargs: Any,
331
336
  ) -> "Optional[Union[dict[str, Any], ModelDTOT]]":
@@ -353,7 +358,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
353
358
  parameters: Optional["StatementParameterType"] = None,
354
359
  /,
355
360
  *,
356
- connection: Optional["Connection"] = None,
361
+ connection: Optional["AiosqliteConnection"] = None,
357
362
  **kwargs: Any,
358
363
  ) -> str:
359
364
  """Execute a script.
@@ -374,7 +379,7 @@ class AiosqliteDriver(AsyncDriverAdapterProtocol["Connection"]):
374
379
  parameters: Optional["StatementParameterType"] = None,
375
380
  /,
376
381
  *,
377
- connection: Optional["Connection"] = None,
382
+ connection: Optional["AiosqliteConnection"] = None,
378
383
  schema_type: "Optional[type[ModelDTOT]]" = None,
379
384
  **kwargs: Any,
380
385
  ) -> "Optional[Union[dict[str, Any], ModelDTOT]]":
@@ -1,8 +1,9 @@
1
1
  from sqlspec.adapters.asyncmy.config import AsyncmyConfig, AsyncmyPoolConfig
2
- from sqlspec.adapters.asyncmy.driver import AsyncmyDriver # type: ignore[attr-defined]
2
+ from sqlspec.adapters.asyncmy.driver import AsyncmyConnection, AsyncmyDriver # type: ignore[attr-defined]
3
3
 
4
4
  __all__ = (
5
5
  "AsyncmyConfig",
6
+ "AsyncmyConnection",
6
7
  "AsyncmyDriver",
7
8
  "AsyncmyPoolConfig",
8
9
  )
@@ -3,33 +3,36 @@ from collections.abc import AsyncGenerator, Sequence
3
3
  from contextlib import asynccontextmanager
4
4
  from typing import TYPE_CHECKING, Any, Optional, Union, cast, overload
5
5
 
6
- from sqlspec.base import AsyncDriverAdapterProtocol, T
6
+ from asyncmy import Connection
7
+
8
+ from sqlspec.base import AsyncDriverAdapterProtocol
9
+ from sqlspec.mixins import SQLTranslatorMixin
7
10
 
8
11
  if TYPE_CHECKING:
9
- from asyncmy import Connection
10
12
  from asyncmy.cursors import Cursor
11
13
 
12
- from sqlspec.typing import ModelDTOT, StatementParameterType
14
+ from sqlspec.typing import ModelDTOT, StatementParameterType, T
13
15
 
14
16
  __all__ = ("AsyncmyDriver",)
15
17
 
18
+ AsyncmyConnection = Connection
19
+
16
20
 
17
- class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
21
+ class AsyncmyDriver(
22
+ SQLTranslatorMixin["AsyncmyConnection"],
23
+ AsyncDriverAdapterProtocol["AsyncmyConnection"],
24
+ ):
18
25
  """Asyncmy MySQL/MariaDB Driver Adapter."""
19
26
 
20
- connection: "Connection"
27
+ connection: "AsyncmyConnection"
21
28
  dialect: str = "mysql"
22
29
 
23
- def __init__(self, connection: "Connection") -> None:
30
+ def __init__(self, connection: "AsyncmyConnection") -> None:
24
31
  self.connection = connection
25
32
 
26
- @staticmethod
27
- async def _cursor(connection: "Connection") -> "Cursor":
28
- return await connection.cursor()
29
-
30
33
  @staticmethod
31
34
  @asynccontextmanager
32
- async def _with_cursor(connection: "Connection") -> AsyncGenerator["Cursor", None]:
35
+ async def _with_cursor(connection: "AsyncmyConnection") -> AsyncGenerator["Cursor", None]:
33
36
  cursor = connection.cursor()
34
37
  try:
35
38
  yield cursor
@@ -44,7 +47,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
44
47
  parameters: "Optional[StatementParameterType]" = None,
45
48
  /,
46
49
  *,
47
- connection: "Optional[Connection]" = None,
50
+ connection: "Optional[AsyncmyConnection]" = None,
48
51
  schema_type: None = None,
49
52
  **kwargs: Any,
50
53
  ) -> "Sequence[dict[str, Any]]": ...
@@ -55,7 +58,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
55
58
  parameters: "Optional[StatementParameterType]" = None,
56
59
  /,
57
60
  *,
58
- connection: "Optional[Connection]" = None,
61
+ connection: "Optional[AsyncmyConnection]" = None,
59
62
  schema_type: "type[ModelDTOT]",
60
63
  **kwargs: Any,
61
64
  ) -> "Sequence[ModelDTOT]": ...
@@ -65,7 +68,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
65
68
  parameters: Optional["StatementParameterType"] = None,
66
69
  /,
67
70
  *,
68
- connection: Optional["Connection"] = None,
71
+ connection: Optional["AsyncmyConnection"] = None,
69
72
  schema_type: "Optional[type[ModelDTOT]]" = None,
70
73
  **kwargs: Any,
71
74
  ) -> "Sequence[Union[ModelDTOT, dict[str, Any]]]":
@@ -93,7 +96,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
93
96
  parameters: "Optional[StatementParameterType]" = None,
94
97
  /,
95
98
  *,
96
- connection: "Optional[Connection]" = None,
99
+ connection: "Optional[AsyncmyConnection]" = None,
97
100
  schema_type: None = None,
98
101
  **kwargs: Any,
99
102
  ) -> "dict[str, Any]": ...
@@ -104,7 +107,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
104
107
  parameters: "Optional[StatementParameterType]" = None,
105
108
  /,
106
109
  *,
107
- connection: "Optional[Connection]" = None,
110
+ connection: "Optional[AsyncmyConnection]" = None,
108
111
  schema_type: "type[ModelDTOT]",
109
112
  **kwargs: Any,
110
113
  ) -> "ModelDTOT": ...
@@ -114,7 +117,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
114
117
  parameters: Optional["StatementParameterType"] = None,
115
118
  /,
116
119
  *,
117
- connection: Optional["Connection"] = None,
120
+ connection: Optional["AsyncmyConnection"] = None,
118
121
  schema_type: "Optional[type[ModelDTOT]]" = None,
119
122
  **kwargs: Any,
120
123
  ) -> "Union[ModelDTOT, dict[str, Any]]":
@@ -141,7 +144,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
141
144
  parameters: "Optional[StatementParameterType]" = None,
142
145
  /,
143
146
  *,
144
- connection: "Optional[Connection]" = None,
147
+ connection: "Optional[AsyncmyConnection]" = None,
145
148
  schema_type: None = None,
146
149
  **kwargs: Any,
147
150
  ) -> "Optional[dict[str, Any]]": ...
@@ -152,7 +155,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
152
155
  parameters: "Optional[StatementParameterType]" = None,
153
156
  /,
154
157
  *,
155
- connection: "Optional[Connection]" = None,
158
+ connection: "Optional[AsyncmyConnection]" = None,
156
159
  schema_type: "type[ModelDTOT]",
157
160
  **kwargs: Any,
158
161
  ) -> "Optional[ModelDTOT]": ...
@@ -162,7 +165,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
162
165
  parameters: Optional["StatementParameterType"] = None,
163
166
  /,
164
167
  *,
165
- connection: Optional["Connection"] = None,
168
+ connection: Optional["AsyncmyConnection"] = None,
166
169
  schema_type: "Optional[type[ModelDTOT]]" = None,
167
170
  **kwargs: Any,
168
171
  ) -> "Optional[Union[ModelDTOT, dict[str, Any]]]":
@@ -190,7 +193,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
190
193
  parameters: "Optional[StatementParameterType]" = None,
191
194
  /,
192
195
  *,
193
- connection: "Optional[Connection]" = None,
196
+ connection: "Optional[AsyncmyConnection]" = None,
194
197
  schema_type: None = None,
195
198
  **kwargs: Any,
196
199
  ) -> "Any": ...
@@ -201,7 +204,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
201
204
  parameters: "Optional[StatementParameterType]" = None,
202
205
  /,
203
206
  *,
204
- connection: "Optional[Connection]" = None,
207
+ connection: "Optional[AsyncmyConnection]" = None,
205
208
  schema_type: "type[T]",
206
209
  **kwargs: Any,
207
210
  ) -> "T": ...
@@ -211,7 +214,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
211
214
  parameters: "Optional[StatementParameterType]" = None,
212
215
  /,
213
216
  *,
214
- connection: "Optional[Connection]" = None,
217
+ connection: "Optional[AsyncmyConnection]" = None,
215
218
  schema_type: "Optional[type[T]]" = None,
216
219
  **kwargs: Any,
217
220
  ) -> "Union[T, Any]":
@@ -240,7 +243,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
240
243
  parameters: "Optional[StatementParameterType]" = None,
241
244
  /,
242
245
  *,
243
- connection: "Optional[Connection]" = None,
246
+ connection: "Optional[AsyncmyConnection]" = None,
244
247
  schema_type: None = None,
245
248
  **kwargs: Any,
246
249
  ) -> "Optional[Any]": ...
@@ -251,7 +254,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
251
254
  parameters: "Optional[StatementParameterType]" = None,
252
255
  /,
253
256
  *,
254
- connection: "Optional[Connection]" = None,
257
+ connection: "Optional[AsyncmyConnection]" = None,
255
258
  schema_type: "type[T]",
256
259
  **kwargs: Any,
257
260
  ) -> "Optional[T]": ...
@@ -261,7 +264,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
261
264
  parameters: "Optional[StatementParameterType]" = None,
262
265
  /,
263
266
  *,
264
- connection: "Optional[Connection]" = None,
267
+ connection: "Optional[AsyncmyConnection]" = None,
265
268
  schema_type: "Optional[type[T]]" = None,
266
269
  **kwargs: Any,
267
270
  ) -> "Optional[Union[T, Any]]":
@@ -291,7 +294,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
291
294
  parameters: Optional["StatementParameterType"] = None,
292
295
  /,
293
296
  *,
294
- connection: Optional["Connection"] = None,
297
+ connection: Optional["AsyncmyConnection"] = None,
295
298
  **kwargs: Any,
296
299
  ) -> int:
297
300
  """Insert, update, or delete data from the database.
@@ -313,7 +316,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
313
316
  parameters: "Optional[StatementParameterType]" = None,
314
317
  /,
315
318
  *,
316
- connection: "Optional[Connection]" = None,
319
+ connection: "Optional[AsyncmyConnection]" = None,
317
320
  schema_type: None = None,
318
321
  **kwargs: Any,
319
322
  ) -> "dict[str, Any]": ...
@@ -324,7 +327,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
324
327
  parameters: "Optional[StatementParameterType]" = None,
325
328
  /,
326
329
  *,
327
- connection: "Optional[Connection]" = None,
330
+ connection: "Optional[AsyncmyConnection]" = None,
328
331
  schema_type: "type[ModelDTOT]",
329
332
  **kwargs: Any,
330
333
  ) -> "ModelDTOT": ...
@@ -334,7 +337,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
334
337
  parameters: Optional["StatementParameterType"] = None,
335
338
  /,
336
339
  *,
337
- connection: Optional["Connection"] = None,
340
+ connection: Optional["AsyncmyConnection"] = None,
338
341
  schema_type: "Optional[type[ModelDTOT]]" = None,
339
342
  **kwargs: Any,
340
343
  ) -> "Optional[Union[dict[str, Any], ModelDTOT]]":
@@ -363,7 +366,7 @@ class AsyncmyDriver(AsyncDriverAdapterProtocol["Connection"]):
363
366
  parameters: Optional["StatementParameterType"] = None,
364
367
  /,
365
368
  *,
366
- connection: Optional["Connection"] = None,
369
+ connection: Optional["AsyncmyConnection"] = None,
367
370
  **kwargs: Any,
368
371
  ) -> str:
369
372
  """Execute a script.
@@ -190,9 +190,7 @@ class AsyncpgConfig(AsyncDatabaseConfig["AsyncpgConnection", "Pool", "AsyncpgDri
190
190
  raise ImproperConfigurationError(msg) from e
191
191
 
192
192
  @asynccontextmanager
193
- async def provide_connection(
194
- self, *args: "Any", **kwargs: "Any"
195
- ) -> "AsyncGenerator[PoolConnectionProxy[Any], None]": # pyright: ignore[reportMissingTypeArgument,reportUnknownParameterType]
193
+ async def provide_connection(self, *args: "Any", **kwargs: "Any") -> "AsyncGenerator[AsyncpgConnection, None]": # pyright: ignore[reportMissingTypeArgument,reportUnknownParameterType]
196
194
  """Create a connection instance.
197
195
 
198
196
  Yields:
@@ -5,8 +5,9 @@ from typing import TYPE_CHECKING, Any, Optional, Union, cast, overload
5
5
  from asyncpg import Connection
6
6
  from typing_extensions import TypeAlias
7
7
 
8
- from sqlspec.base import AsyncDriverAdapterProtocol, T
8
+ from sqlspec.base import AsyncDriverAdapterProtocol
9
9
  from sqlspec.exceptions import SQLParsingError
10
+ from sqlspec.mixins import SQLTranslatorMixin
10
11
  from sqlspec.statement import PARAM_REGEX, SQLStatement
11
12
 
12
13
  if TYPE_CHECKING:
@@ -15,7 +16,7 @@ if TYPE_CHECKING:
15
16
  from asyncpg.connection import Connection
16
17
  from asyncpg.pool import PoolConnectionProxy
17
18
 
18
- from sqlspec.typing import ModelDTOT, StatementParameterType
19
+ from sqlspec.typing import ModelDTOT, StatementParameterType, T
19
20
 
20
21
  __all__ = ("AsyncpgConnection", "AsyncpgDriver")
21
22
 
@@ -35,7 +36,10 @@ QMARK_REGEX = re.compile(
35
36
  AsyncpgConnection: TypeAlias = "Union[Connection[Any], PoolConnectionProxy[Any]]" # pyright: ignore[reportMissingTypeArgument]
36
37
 
37
38
 
38
- class AsyncpgDriver(AsyncDriverAdapterProtocol["AsyncpgConnection"]):
39
+ class AsyncpgDriver(
40
+ SQLTranslatorMixin["AsyncpgConnection"],
41
+ AsyncDriverAdapterProtocol["AsyncpgConnection"],
42
+ ):
39
43
  """AsyncPG Postgres Driver Adapter."""
40
44
 
41
45
  connection: "AsyncpgConnection"
@@ -0,0 +1,4 @@
1
+ from sqlspec.adapters.bigquery.config import BigQueryConfig, BigQueryConnectionConfig
2
+ from sqlspec.adapters.bigquery.driver import BigQueryConnection, BigQueryDriver
3
+
4
+ __all__ = ("BigQueryConfig", "BigQueryConnection", "BigQueryConnectionConfig", "BigQueryDriver")
@@ -0,0 +1,3 @@
1
+ from sqlspec.adapters.bigquery.config._sync import BigQueryConfig, BigQueryConnectionConfig
2
+
3
+ __all__ = ("BigQueryConfig", "BigQueryConnectionConfig")
@@ -0,0 +1,40 @@
1
+ from dataclasses import dataclass, field
2
+ from typing import TYPE_CHECKING, Optional
3
+
4
+ from google.cloud.bigquery import LoadJobConfig, QueryJobConfig
5
+
6
+ if TYPE_CHECKING:
7
+ from google.api_core.client_info import ClientInfo
8
+ from google.api_core.client_options import ClientOptions
9
+ from google.auth.credentials import Credentials
10
+
11
+ __all__ = ("BigQueryConnectionConfigCommon",)
12
+
13
+
14
+ @dataclass
15
+ class BigQueryConnectionConfigCommon:
16
+ """Common configuration options for BigQuery."""
17
+
18
+ project: "Optional[str]" = field(default=None)
19
+ """Google Cloud project ID."""
20
+ location: "Optional[str]" = field(default=None)
21
+ """Default geographic location for jobs and datasets."""
22
+ credentials: "Optional[Credentials]" = field(default=None, hash=False)
23
+ """Credentials to use for authentication."""
24
+ dataset_id: "Optional[str]" = field(default=None)
25
+ """Default dataset ID to use if not specified in queries."""
26
+ credentials_path: "Optional[str]" = field(default=None)
27
+ """Path to Google Cloud service account key file (JSON). If None, attempts default authentication."""
28
+ client_options: "Optional[ClientOptions]" = field(default=None, hash=False)
29
+ """Client options used to set user options on the client (e.g., api_endpoint)."""
30
+ default_query_job_config: "Optional[QueryJobConfig]" = field(default=None, hash=False)
31
+ """Default QueryJobConfig settings."""
32
+ default_load_job_config: "Optional[LoadJobConfig]" = field(default=None, hash=False)
33
+ """Default LoadJobConfig settings."""
34
+ client_info: "Optional[ClientInfo]" = field(default=None, hash=False)
35
+ """Client info used to send a user-agent string along with API requests."""
36
+
37
+ def __post_init__(self) -> None:
38
+ """Post-initialization hook."""
39
+ if self.default_query_job_config is None:
40
+ self.default_query_job_config = QueryJobConfig(default_dataset=self.dataset_id)
@@ -0,0 +1,87 @@
1
+ import contextlib
2
+ from dataclasses import dataclass, field
3
+ from typing import TYPE_CHECKING, Any, Optional
4
+
5
+ from sqlspec.adapters.bigquery.config._common import BigQueryConnectionConfigCommon
6
+ from sqlspec.adapters.bigquery.driver import BigQueryConnection, BigQueryDriver
7
+ from sqlspec.base import NoPoolSyncConfig
8
+ from sqlspec.typing import dataclass_to_dict
9
+
10
+ if TYPE_CHECKING:
11
+ from collections.abc import Iterator
12
+
13
+ __all__ = ("BigQueryConfig", "BigQueryConnectionConfig")
14
+
15
+
16
+ class BigQueryConnectionConfig(BigQueryConnectionConfigCommon):
17
+ """BigQuery Connection Configuration."""
18
+
19
+
20
+ @dataclass
21
+ class BigQueryConfig(NoPoolSyncConfig["BigQueryConnection", "BigQueryDriver"]):
22
+ """BigQuery Synchronous Driver Configuration."""
23
+
24
+ connection_config: "BigQueryConnectionConfig" = field(default_factory=BigQueryConnectionConfig)
25
+ """BigQuery Connection Configuration."""
26
+ driver_type: "type[BigQueryDriver]" = field(init=False, repr=False, default=BigQueryDriver)
27
+ """BigQuery Driver Type."""
28
+ connection_type: "type[BigQueryConnection]" = field(init=False, repr=False, default=BigQueryConnection)
29
+ """BigQuery Connection Type."""
30
+ pool_instance: "None" = field(init=False, repr=False, default=None, hash=False)
31
+ """This is set to have a init=False since BigQuery does not support pooling."""
32
+ connection_instance: "Optional[BigQueryConnection]" = field(init=False, repr=False, default=None, hash=False)
33
+ """BigQuery Connection Instance."""
34
+
35
+ @property
36
+ def connection_config_dict(self) -> "dict[str, Any]":
37
+ """Return the connection configuration as a dict.
38
+
39
+ Returns:
40
+ A string keyed dict of config kwargs for the BigQueryConnection constructor.
41
+ """
42
+ return dataclass_to_dict(
43
+ self.connection_config,
44
+ exclude_empty=True,
45
+ exclude_none=True,
46
+ exclude={"dataset_id", "credentials_path"},
47
+ )
48
+
49
+ def create_connection(self) -> "BigQueryConnection":
50
+ """Create a BigQuery Client instance.
51
+
52
+ Returns:
53
+ A BigQuery Client instance.
54
+ """
55
+ if self.connection_instance is not None:
56
+ return self.connection_instance
57
+
58
+ self.connection_instance = self.connection_type(**self.connection_config_dict)
59
+ return self.connection_instance
60
+
61
+ @contextlib.contextmanager
62
+ def provide_connection(self, *args: Any, **kwargs: Any) -> "Iterator[BigQueryConnection]":
63
+ """Provide a BigQuery client within a context manager.
64
+
65
+ Args:
66
+ *args: Additional arguments to pass to the connection.
67
+ **kwargs: Additional keyword arguments to pass to the connection.
68
+
69
+ Yields:
70
+ An iterator of BigQuery Client instances.
71
+ """
72
+ conn = self.create_connection()
73
+ yield conn
74
+
75
+ @contextlib.contextmanager
76
+ def provide_session(self, *args: Any, **kwargs: Any) -> "Iterator[BigQueryDriver]":
77
+ """Provide a BigQuery driver session within a context manager.
78
+
79
+ Args:
80
+ *args: Additional arguments to pass to the driver.
81
+ **kwargs: Additional keyword arguments to pass to the driver.
82
+
83
+ Yields:
84
+ An iterator of BigQueryDriver instances.
85
+ """
86
+ conn = self.create_connection()
87
+ yield self.driver_type(connection=conn)