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
sqlspec/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from sqlspec import adapters, base, exceptions, extensions, filters, typing, utils
|
|
1
|
+
from sqlspec import adapters, base, exceptions, extensions, filters, mixins, typing, utils
|
|
2
2
|
from sqlspec.__metadata__ import __version__
|
|
3
3
|
from sqlspec.base import SQLSpec
|
|
4
4
|
|
|
@@ -10,6 +10,7 @@ __all__ = (
|
|
|
10
10
|
"exceptions",
|
|
11
11
|
"extensions",
|
|
12
12
|
"filters",
|
|
13
|
+
"mixins",
|
|
13
14
|
"typing",
|
|
14
15
|
"utils",
|
|
15
16
|
)
|
sqlspec/adapters/adbc/config.py
CHANGED
|
@@ -2,9 +2,7 @@ from contextlib import contextmanager
|
|
|
2
2
|
from dataclasses import dataclass, field
|
|
3
3
|
from typing import TYPE_CHECKING, Any, Callable, Optional, Union, cast
|
|
4
4
|
|
|
5
|
-
from
|
|
6
|
-
|
|
7
|
-
from sqlspec.adapters.adbc.driver import AdbcDriver
|
|
5
|
+
from sqlspec.adapters.adbc.driver import AdbcConnection, AdbcDriver
|
|
8
6
|
from sqlspec.base import NoPoolSyncConfig
|
|
9
7
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
10
8
|
from sqlspec.typing import Empty, EmptyType
|
|
@@ -18,7 +16,7 @@ __all__ = ("AdbcConfig",)
|
|
|
18
16
|
|
|
19
17
|
|
|
20
18
|
@dataclass
|
|
21
|
-
class AdbcConfig(NoPoolSyncConfig["
|
|
19
|
+
class AdbcConfig(NoPoolSyncConfig["AdbcConnection", "AdbcDriver"]):
|
|
22
20
|
"""Configuration for ADBC connections.
|
|
23
21
|
|
|
24
22
|
This class provides configuration options for ADBC database connections using the
|
|
@@ -33,20 +31,16 @@ class AdbcConfig(NoPoolSyncConfig["Connection", "AdbcDriver"]):
|
|
|
33
31
|
"""Additional database-specific connection parameters"""
|
|
34
32
|
conn_kwargs: "Optional[dict[str, Any]]" = None
|
|
35
33
|
"""Additional database-specific connection parameters"""
|
|
36
|
-
connection_type: "type[
|
|
34
|
+
connection_type: "type[AdbcConnection]" = field(init=False, default_factory=lambda: AdbcConnection)
|
|
37
35
|
"""Type of the connection object"""
|
|
38
36
|
driver_type: "type[AdbcDriver]" = field(init=False, default_factory=lambda: AdbcDriver) # type: ignore[type-abstract,unused-ignore]
|
|
39
37
|
"""Type of the driver object"""
|
|
40
|
-
pool_instance: None = field(init=False, default=None)
|
|
38
|
+
pool_instance: None = field(init=False, default=None, hash=False)
|
|
41
39
|
"""No connection pool is used for ADBC connections"""
|
|
42
|
-
_is_in_memory: bool = field(init=False, default=False)
|
|
43
|
-
"""Flag indicating if the connection is for an in-memory database"""
|
|
44
40
|
|
|
45
41
|
def _set_adbc(self) -> str: # noqa: PLR0912
|
|
46
42
|
"""Identify the driver type based on the URI (if provided) or preset driver name.
|
|
47
43
|
|
|
48
|
-
Also sets the `_is_in_memory` flag for specific in-memory URIs.
|
|
49
|
-
|
|
50
44
|
Raises:
|
|
51
45
|
ImproperConfigurationError: If the driver name is not recognized or supported.
|
|
52
46
|
|
|
@@ -143,7 +137,7 @@ class AdbcConfig(NoPoolSyncConfig["Connection", "AdbcDriver"]):
|
|
|
143
137
|
config["conn_kwargs"] = conn_kwargs
|
|
144
138
|
return config
|
|
145
139
|
|
|
146
|
-
def _get_connect_func(self) -> "Callable[...,
|
|
140
|
+
def _get_connect_func(self) -> "Callable[..., AdbcConnection]":
|
|
147
141
|
self._set_adbc()
|
|
148
142
|
driver_path = cast("str", self.driver_name)
|
|
149
143
|
try:
|
|
@@ -166,7 +160,7 @@ class AdbcConfig(NoPoolSyncConfig["Connection", "AdbcDriver"]):
|
|
|
166
160
|
raise ImproperConfigurationError(msg)
|
|
167
161
|
return connect_func # type: ignore[no-any-return]
|
|
168
162
|
|
|
169
|
-
def create_connection(self) -> "
|
|
163
|
+
def create_connection(self) -> "AdbcConnection":
|
|
170
164
|
"""Create and return a new database connection using the specific driver.
|
|
171
165
|
|
|
172
166
|
Returns:
|
|
@@ -189,7 +183,7 @@ class AdbcConfig(NoPoolSyncConfig["Connection", "AdbcDriver"]):
|
|
|
189
183
|
raise ImproperConfigurationError(msg) from e
|
|
190
184
|
|
|
191
185
|
@contextmanager
|
|
192
|
-
def provide_connection(self, *args: "Any", **kwargs: "Any") -> "Generator[
|
|
186
|
+
def provide_connection(self, *args: "Any", **kwargs: "Any") -> "Generator[AdbcConnection, None, None]":
|
|
193
187
|
"""Create and provide a database connection using the specific driver.
|
|
194
188
|
|
|
195
189
|
Yields:
|
sqlspec/adapters/adbc/driver.py
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import contextlib
|
|
2
2
|
import logging
|
|
3
3
|
import re
|
|
4
|
-
from collections.abc import Generator
|
|
4
|
+
from collections.abc import Generator, Sequence
|
|
5
5
|
from contextlib import contextmanager
|
|
6
|
-
from typing import TYPE_CHECKING, Any, ClassVar, Optional, Union, cast
|
|
6
|
+
from typing import TYPE_CHECKING, Any, ClassVar, Optional, Union, cast, overload
|
|
7
7
|
|
|
8
8
|
from adbc_driver_manager.dbapi import Connection, Cursor
|
|
9
9
|
|
|
10
|
-
from sqlspec.base import
|
|
10
|
+
from sqlspec.base import SyncDriverAdapterProtocol
|
|
11
11
|
from sqlspec.exceptions import ParameterStyleMismatchError, SQLParsingError
|
|
12
|
+
from sqlspec.mixins import SQLTranslatorMixin, SyncArrowBulkOperationsMixin
|
|
12
13
|
from sqlspec.statement import SQLStatement
|
|
13
14
|
from sqlspec.typing import ArrowTable, StatementParameterType
|
|
14
15
|
|
|
15
16
|
if TYPE_CHECKING:
|
|
16
|
-
from sqlspec.typing import ArrowTable, ModelDTOT, StatementParameterType
|
|
17
|
+
from sqlspec.typing import ArrowTable, ModelDTOT, StatementParameterType, T
|
|
17
18
|
|
|
18
|
-
__all__ = ("AdbcDriver"
|
|
19
|
+
__all__ = ("AdbcConnection", "AdbcDriver")
|
|
19
20
|
|
|
20
21
|
logger = logging.getLogger("sqlspec")
|
|
21
22
|
|
|
@@ -32,20 +33,26 @@ PARAM_REGEX = re.compile(
|
|
|
32
33
|
re.VERBOSE | re.DOTALL,
|
|
33
34
|
)
|
|
34
35
|
|
|
36
|
+
AdbcConnection = Connection
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
|
|
39
|
+
class AdbcDriver(
|
|
40
|
+
SyncArrowBulkOperationsMixin["AdbcConnection"],
|
|
41
|
+
SQLTranslatorMixin["AdbcConnection"],
|
|
42
|
+
SyncDriverAdapterProtocol["AdbcConnection"],
|
|
43
|
+
):
|
|
37
44
|
"""ADBC Sync Driver Adapter."""
|
|
38
45
|
|
|
39
|
-
connection:
|
|
46
|
+
connection: AdbcConnection
|
|
40
47
|
__supports_arrow__: ClassVar[bool] = True
|
|
41
48
|
|
|
42
|
-
def __init__(self, connection: "
|
|
49
|
+
def __init__(self, connection: "AdbcConnection") -> None:
|
|
43
50
|
"""Initialize the ADBC driver adapter."""
|
|
44
51
|
self.connection = connection
|
|
45
52
|
self.dialect = self._get_dialect(connection)
|
|
46
53
|
|
|
47
54
|
@staticmethod
|
|
48
|
-
def _get_dialect(connection: "
|
|
55
|
+
def _get_dialect(connection: "AdbcConnection") -> str: # noqa: PLR0911
|
|
49
56
|
"""Get the database dialect based on the driver name.
|
|
50
57
|
|
|
51
58
|
Args:
|
|
@@ -70,11 +77,11 @@ class AdbcDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAdapterPr
|
|
|
70
77
|
return "postgres" # default to postgresql dialect
|
|
71
78
|
|
|
72
79
|
@staticmethod
|
|
73
|
-
def _cursor(connection: "
|
|
80
|
+
def _cursor(connection: "AdbcConnection", *args: Any, **kwargs: Any) -> "Cursor":
|
|
74
81
|
return connection.cursor(*args, **kwargs)
|
|
75
82
|
|
|
76
83
|
@contextmanager
|
|
77
|
-
def _with_cursor(self, connection: "
|
|
84
|
+
def _with_cursor(self, connection: "AdbcConnection") -> Generator["Cursor", None, None]:
|
|
78
85
|
cursor = self._cursor(connection)
|
|
79
86
|
try:
|
|
80
87
|
yield cursor
|
|
@@ -160,16 +167,38 @@ class AdbcDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAdapterPr
|
|
|
160
167
|
stmt = SQLStatement(sql=sql, parameters=parameters, dialect=self.dialect, kwargs=kwargs or None)
|
|
161
168
|
return stmt.process()
|
|
162
169
|
|
|
170
|
+
@overload
|
|
171
|
+
def select(
|
|
172
|
+
self,
|
|
173
|
+
sql: str,
|
|
174
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
175
|
+
/,
|
|
176
|
+
*,
|
|
177
|
+
connection: "Optional[AdbcConnection]" = None,
|
|
178
|
+
schema_type: None = None,
|
|
179
|
+
**kwargs: Any,
|
|
180
|
+
) -> "Sequence[dict[str, Any]]": ...
|
|
181
|
+
@overload
|
|
182
|
+
def select(
|
|
183
|
+
self,
|
|
184
|
+
sql: str,
|
|
185
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
186
|
+
/,
|
|
187
|
+
*,
|
|
188
|
+
connection: "Optional[AdbcConnection]" = None,
|
|
189
|
+
schema_type: "type[ModelDTOT]",
|
|
190
|
+
**kwargs: Any,
|
|
191
|
+
) -> "Sequence[ModelDTOT]": ...
|
|
163
192
|
def select(
|
|
164
193
|
self,
|
|
165
194
|
sql: str,
|
|
166
195
|
parameters: Optional["StatementParameterType"] = None,
|
|
167
196
|
/,
|
|
168
197
|
*,
|
|
169
|
-
connection: Optional["
|
|
198
|
+
connection: Optional["AdbcConnection"] = None,
|
|
170
199
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
171
200
|
**kwargs: Any,
|
|
172
|
-
) -> "
|
|
201
|
+
) -> "Sequence[Union[ModelDTOT, dict[str, Any]]]":
|
|
173
202
|
"""Fetch data from the database.
|
|
174
203
|
|
|
175
204
|
Returns:
|
|
@@ -189,13 +218,35 @@ class AdbcDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAdapterPr
|
|
|
189
218
|
return [cast("ModelDTOT", schema_type(**dict(zip(column_names, row)))) for row in results] # pyright: ignore[reportUnknownArgumentType,reportUnknownVariableType]
|
|
190
219
|
return [dict(zip(column_names, row)) for row in results] # pyright: ignore[reportUnknownArgumentType,reportUnknownVariableType]
|
|
191
220
|
|
|
221
|
+
@overload
|
|
222
|
+
def select_one(
|
|
223
|
+
self,
|
|
224
|
+
sql: str,
|
|
225
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
226
|
+
/,
|
|
227
|
+
*,
|
|
228
|
+
connection: "Optional[AdbcConnection]" = None,
|
|
229
|
+
schema_type: None = None,
|
|
230
|
+
**kwargs: Any,
|
|
231
|
+
) -> "dict[str, Any]": ...
|
|
232
|
+
@overload
|
|
233
|
+
def select_one(
|
|
234
|
+
self,
|
|
235
|
+
sql: str,
|
|
236
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
237
|
+
/,
|
|
238
|
+
*,
|
|
239
|
+
connection: "Optional[AdbcConnection]" = None,
|
|
240
|
+
schema_type: "type[ModelDTOT]",
|
|
241
|
+
**kwargs: Any,
|
|
242
|
+
) -> "ModelDTOT": ...
|
|
192
243
|
def select_one(
|
|
193
244
|
self,
|
|
194
245
|
sql: str,
|
|
195
246
|
parameters: Optional["StatementParameterType"] = None,
|
|
196
247
|
/,
|
|
197
248
|
*,
|
|
198
|
-
connection: Optional["
|
|
249
|
+
connection: Optional["AdbcConnection"] = None,
|
|
199
250
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
200
251
|
**kwargs: Any,
|
|
201
252
|
) -> "Union[ModelDTOT, dict[str, Any]]":
|
|
@@ -215,13 +266,35 @@ class AdbcDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAdapterPr
|
|
|
215
266
|
return dict(zip(column_names, result)) # pyright: ignore[reportUnknownArgumentType, reportUnknownVariableType]
|
|
216
267
|
return schema_type(**dict(zip(column_names, result))) # type: ignore[return-value]
|
|
217
268
|
|
|
269
|
+
@overload
|
|
270
|
+
def select_one_or_none(
|
|
271
|
+
self,
|
|
272
|
+
sql: str,
|
|
273
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
274
|
+
/,
|
|
275
|
+
*,
|
|
276
|
+
connection: "Optional[AdbcConnection]" = None,
|
|
277
|
+
schema_type: None = None,
|
|
278
|
+
**kwargs: Any,
|
|
279
|
+
) -> "Optional[dict[str, Any]]": ...
|
|
280
|
+
@overload
|
|
281
|
+
def select_one_or_none(
|
|
282
|
+
self,
|
|
283
|
+
sql: str,
|
|
284
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
285
|
+
/,
|
|
286
|
+
*,
|
|
287
|
+
connection: "Optional[AdbcConnection]" = None,
|
|
288
|
+
schema_type: "type[ModelDTOT]",
|
|
289
|
+
**kwargs: Any,
|
|
290
|
+
) -> "Optional[ModelDTOT]": ...
|
|
218
291
|
def select_one_or_none(
|
|
219
292
|
self,
|
|
220
293
|
sql: str,
|
|
221
294
|
parameters: Optional["StatementParameterType"] = None,
|
|
222
295
|
/,
|
|
223
296
|
*,
|
|
224
|
-
connection: Optional["
|
|
297
|
+
connection: Optional["AdbcConnection"] = None,
|
|
225
298
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
226
299
|
**kwargs: Any,
|
|
227
300
|
) -> "Optional[Union[ModelDTOT, dict[str, Any]]]":
|
|
@@ -242,13 +315,35 @@ class AdbcDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAdapterPr
|
|
|
242
315
|
return dict(zip(column_names, result)) # pyright: ignore[reportUnknownArgumentType, reportUnknownVariableType]
|
|
243
316
|
return schema_type(**dict(zip(column_names, result))) # type: ignore[return-value]
|
|
244
317
|
|
|
318
|
+
@overload
|
|
319
|
+
def select_value(
|
|
320
|
+
self,
|
|
321
|
+
sql: str,
|
|
322
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
323
|
+
/,
|
|
324
|
+
*,
|
|
325
|
+
connection: "Optional[AdbcConnection]" = None,
|
|
326
|
+
schema_type: None = None,
|
|
327
|
+
**kwargs: Any,
|
|
328
|
+
) -> "Any": ...
|
|
329
|
+
@overload
|
|
330
|
+
def select_value(
|
|
331
|
+
self,
|
|
332
|
+
sql: str,
|
|
333
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
334
|
+
/,
|
|
335
|
+
*,
|
|
336
|
+
connection: "Optional[AdbcConnection]" = None,
|
|
337
|
+
schema_type: "type[T]",
|
|
338
|
+
**kwargs: Any,
|
|
339
|
+
) -> "T": ...
|
|
245
340
|
def select_value(
|
|
246
341
|
self,
|
|
247
342
|
sql: str,
|
|
248
343
|
parameters: Optional["StatementParameterType"] = None,
|
|
249
344
|
/,
|
|
250
345
|
*,
|
|
251
|
-
connection: Optional["
|
|
346
|
+
connection: Optional["AdbcConnection"] = None,
|
|
252
347
|
schema_type: "Optional[type[T]]" = None,
|
|
253
348
|
**kwargs: Any,
|
|
254
349
|
) -> "Union[T, Any]":
|
|
@@ -267,13 +362,35 @@ class AdbcDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAdapterPr
|
|
|
267
362
|
return result[0] # pyright: ignore[reportUnknownVariableType]
|
|
268
363
|
return schema_type(result[0]) # type: ignore[call-arg]
|
|
269
364
|
|
|
365
|
+
@overload
|
|
366
|
+
def select_value_or_none(
|
|
367
|
+
self,
|
|
368
|
+
sql: str,
|
|
369
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
370
|
+
/,
|
|
371
|
+
*,
|
|
372
|
+
connection: "Optional[AdbcConnection]" = None,
|
|
373
|
+
schema_type: None = None,
|
|
374
|
+
**kwargs: Any,
|
|
375
|
+
) -> "Optional[Any]": ...
|
|
376
|
+
@overload
|
|
377
|
+
def select_value_or_none(
|
|
378
|
+
self,
|
|
379
|
+
sql: str,
|
|
380
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
381
|
+
/,
|
|
382
|
+
*,
|
|
383
|
+
connection: "Optional[AdbcConnection]" = None,
|
|
384
|
+
schema_type: "type[T]",
|
|
385
|
+
**kwargs: Any,
|
|
386
|
+
) -> "Optional[T]": ...
|
|
270
387
|
def select_value_or_none(
|
|
271
388
|
self,
|
|
272
389
|
sql: str,
|
|
273
390
|
parameters: Optional["StatementParameterType"] = None,
|
|
274
391
|
/,
|
|
275
392
|
*,
|
|
276
|
-
connection: Optional["
|
|
393
|
+
connection: Optional["AdbcConnection"] = None,
|
|
277
394
|
schema_type: "Optional[type[T]]" = None,
|
|
278
395
|
**kwargs: Any,
|
|
279
396
|
) -> "Optional[Union[T, Any]]":
|
|
@@ -299,7 +416,7 @@ class AdbcDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAdapterPr
|
|
|
299
416
|
parameters: Optional["StatementParameterType"] = None,
|
|
300
417
|
/,
|
|
301
418
|
*,
|
|
302
|
-
connection: Optional["
|
|
419
|
+
connection: Optional["AdbcConnection"] = None,
|
|
303
420
|
**kwargs: Any,
|
|
304
421
|
) -> int:
|
|
305
422
|
"""Insert, update, or delete data from the database.
|
|
@@ -314,13 +431,35 @@ class AdbcDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAdapterPr
|
|
|
314
431
|
cursor.execute(sql, parameters) # pyright: ignore[reportUnknownMemberType]
|
|
315
432
|
return cursor.rowcount if hasattr(cursor, "rowcount") else -1
|
|
316
433
|
|
|
434
|
+
@overload
|
|
435
|
+
def insert_update_delete_returning(
|
|
436
|
+
self,
|
|
437
|
+
sql: str,
|
|
438
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
439
|
+
/,
|
|
440
|
+
*,
|
|
441
|
+
connection: "Optional[AdbcConnection]" = None,
|
|
442
|
+
schema_type: None = None,
|
|
443
|
+
**kwargs: Any,
|
|
444
|
+
) -> "dict[str, Any]": ...
|
|
445
|
+
@overload
|
|
446
|
+
def insert_update_delete_returning(
|
|
447
|
+
self,
|
|
448
|
+
sql: str,
|
|
449
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
450
|
+
/,
|
|
451
|
+
*,
|
|
452
|
+
connection: "Optional[AdbcConnection]" = None,
|
|
453
|
+
schema_type: "type[ModelDTOT]",
|
|
454
|
+
**kwargs: Any,
|
|
455
|
+
) -> "ModelDTOT": ...
|
|
317
456
|
def insert_update_delete_returning(
|
|
318
457
|
self,
|
|
319
458
|
sql: str,
|
|
320
459
|
parameters: Optional["StatementParameterType"] = None,
|
|
321
460
|
/,
|
|
322
461
|
*,
|
|
323
|
-
connection: Optional["
|
|
462
|
+
connection: Optional["AdbcConnection"] = None,
|
|
324
463
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
325
464
|
**kwargs: Any,
|
|
326
465
|
) -> "Optional[Union[dict[str, Any], ModelDTOT]]":
|
|
@@ -353,7 +492,7 @@ class AdbcDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAdapterPr
|
|
|
353
492
|
parameters: Optional["StatementParameterType"] = None,
|
|
354
493
|
/,
|
|
355
494
|
*,
|
|
356
|
-
connection: Optional["
|
|
495
|
+
connection: Optional["AdbcConnection"] = None,
|
|
357
496
|
**kwargs: Any,
|
|
358
497
|
) -> str:
|
|
359
498
|
"""Execute a script.
|
|
@@ -376,7 +515,7 @@ class AdbcDriver(SyncArrowBulkOperationsMixin["Connection"], SyncDriverAdapterPr
|
|
|
376
515
|
parameters: "Optional[StatementParameterType]" = None,
|
|
377
516
|
/,
|
|
378
517
|
*,
|
|
379
|
-
connection: "Optional[
|
|
518
|
+
connection: "Optional[AdbcConnection]" = None,
|
|
380
519
|
**kwargs: Any,
|
|
381
520
|
) -> "ArrowTable":
|
|
382
521
|
"""Execute a SQL query and return results as an Apache Arrow Table.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
from sqlspec.adapters.aiosqlite.config import AiosqliteConfig
|
|
2
|
-
from sqlspec.adapters.aiosqlite.driver import AiosqliteDriver
|
|
2
|
+
from sqlspec.adapters.aiosqlite.driver import AiosqliteConnection, AiosqliteDriver
|
|
3
3
|
|
|
4
4
|
__all__ = (
|
|
5
5
|
"AiosqliteConfig",
|
|
6
|
+
"AiosqliteConnection",
|
|
6
7
|
"AiosqliteDriver",
|
|
7
8
|
)
|
|
@@ -2,16 +2,15 @@ from contextlib import asynccontextmanager
|
|
|
2
2
|
from dataclasses import dataclass, field
|
|
3
3
|
from typing import TYPE_CHECKING, Any, Optional, Union
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import aiosqlite
|
|
6
6
|
|
|
7
|
-
from sqlspec.adapters.aiosqlite.driver import AiosqliteDriver
|
|
7
|
+
from sqlspec.adapters.aiosqlite.driver import AiosqliteConnection, AiosqliteDriver
|
|
8
8
|
from sqlspec.base import NoPoolAsyncConfig
|
|
9
9
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
10
10
|
from sqlspec.typing import Empty, EmptyType, dataclass_to_dict
|
|
11
11
|
|
|
12
12
|
if TYPE_CHECKING:
|
|
13
13
|
from collections.abc import AsyncGenerator
|
|
14
|
-
from sqlite3 import Connection as SQLite3Connection
|
|
15
14
|
from typing import Literal
|
|
16
15
|
|
|
17
16
|
|
|
@@ -19,7 +18,7 @@ __all__ = ("AiosqliteConfig",)
|
|
|
19
18
|
|
|
20
19
|
|
|
21
20
|
@dataclass
|
|
22
|
-
class AiosqliteConfig(NoPoolAsyncConfig["
|
|
21
|
+
class AiosqliteConfig(NoPoolAsyncConfig["AiosqliteConnection", "AiosqliteDriver"]):
|
|
23
22
|
"""Configuration for Aiosqlite database connections.
|
|
24
23
|
|
|
25
24
|
This class provides configuration options for Aiosqlite database connections, wrapping all parameters
|
|
@@ -38,13 +37,11 @@ class AiosqliteConfig(NoPoolAsyncConfig["Connection", "AiosqliteDriver"]):
|
|
|
38
37
|
"""The isolation_level of the connection. This can be None for autocommit mode or one of "DEFERRED", "IMMEDIATE" or "EXCLUSIVE"."""
|
|
39
38
|
check_same_thread: "Union[bool, EmptyType]" = field(default=Empty)
|
|
40
39
|
"""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."""
|
|
41
|
-
factory: "Union[type[SQLite3Connection], EmptyType]" = field(default=Empty)
|
|
42
|
-
"""A custom Connection class factory. If given, must be a callable that returns a Connection instance."""
|
|
43
40
|
cached_statements: "Union[int, EmptyType]" = field(default=Empty)
|
|
44
41
|
"""The number of statements that SQLite will cache for this connection. The default is 128."""
|
|
45
42
|
uri: "Union[bool, EmptyType]" = field(default=Empty)
|
|
46
43
|
"""If set to True, database is interpreted as a URI with supported options."""
|
|
47
|
-
connection_type: "type[
|
|
44
|
+
connection_type: "type[AiosqliteConnection]" = field(init=False, default_factory=lambda: AiosqliteConnection)
|
|
48
45
|
"""Type of the connection object"""
|
|
49
46
|
driver_type: "type[AiosqliteDriver]" = field(init=False, default_factory=lambda: AiosqliteDriver) # type: ignore[type-abstract,unused-ignore]
|
|
50
47
|
"""Type of the driver object"""
|
|
@@ -57,10 +54,13 @@ class AiosqliteConfig(NoPoolAsyncConfig["Connection", "AiosqliteDriver"]):
|
|
|
57
54
|
A string keyed dict of config kwargs for the aiosqlite.connect() function.
|
|
58
55
|
"""
|
|
59
56
|
return dataclass_to_dict(
|
|
60
|
-
self,
|
|
57
|
+
self,
|
|
58
|
+
exclude_empty=True,
|
|
59
|
+
convert_nested=False,
|
|
60
|
+
exclude={"pool_instance", "connection_type", "driver_type"},
|
|
61
61
|
)
|
|
62
62
|
|
|
63
|
-
async def create_connection(self) -> "
|
|
63
|
+
async def create_connection(self) -> "AiosqliteConnection":
|
|
64
64
|
"""Create and return a new database connection.
|
|
65
65
|
|
|
66
66
|
Returns:
|
|
@@ -69,8 +69,6 @@ class AiosqliteConfig(NoPoolAsyncConfig["Connection", "AiosqliteDriver"]):
|
|
|
69
69
|
Raises:
|
|
70
70
|
ImproperConfigurationError: If the connection could not be established.
|
|
71
71
|
"""
|
|
72
|
-
import aiosqlite
|
|
73
|
-
|
|
74
72
|
try:
|
|
75
73
|
return await aiosqlite.connect(**self.connection_config_dict)
|
|
76
74
|
except Exception as e:
|
|
@@ -78,7 +76,7 @@ class AiosqliteConfig(NoPoolAsyncConfig["Connection", "AiosqliteDriver"]):
|
|
|
78
76
|
raise ImproperConfigurationError(msg) from e
|
|
79
77
|
|
|
80
78
|
@asynccontextmanager
|
|
81
|
-
async def provide_connection(self, *args: "Any", **kwargs: "Any") -> "AsyncGenerator[
|
|
79
|
+
async def provide_connection(self, *args: "Any", **kwargs: "Any") -> "AsyncGenerator[AiosqliteConnection, None]":
|
|
82
80
|
"""Create and provide a database connection.
|
|
83
81
|
|
|
84
82
|
Yields:
|