sqlspec 0.11.1__py3-none-any.whl → 0.12.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/__init__.py +16 -3
- sqlspec/_serialization.py +3 -10
- sqlspec/_sql.py +1147 -0
- sqlspec/_typing.py +343 -41
- sqlspec/adapters/adbc/__init__.py +2 -6
- sqlspec/adapters/adbc/config.py +474 -149
- sqlspec/adapters/adbc/driver.py +330 -621
- sqlspec/adapters/aiosqlite/__init__.py +2 -6
- sqlspec/adapters/aiosqlite/config.py +143 -57
- sqlspec/adapters/aiosqlite/driver.py +269 -431
- sqlspec/adapters/asyncmy/__init__.py +3 -8
- sqlspec/adapters/asyncmy/config.py +247 -202
- sqlspec/adapters/asyncmy/driver.py +218 -436
- sqlspec/adapters/asyncpg/__init__.py +4 -7
- sqlspec/adapters/asyncpg/config.py +329 -176
- sqlspec/adapters/asyncpg/driver.py +417 -487
- sqlspec/adapters/bigquery/__init__.py +2 -2
- sqlspec/adapters/bigquery/config.py +407 -0
- sqlspec/adapters/bigquery/driver.py +600 -553
- sqlspec/adapters/duckdb/__init__.py +4 -1
- sqlspec/adapters/duckdb/config.py +432 -321
- sqlspec/adapters/duckdb/driver.py +392 -406
- sqlspec/adapters/oracledb/__init__.py +3 -8
- sqlspec/adapters/oracledb/config.py +625 -0
- sqlspec/adapters/oracledb/driver.py +548 -921
- sqlspec/adapters/psqlpy/__init__.py +4 -7
- sqlspec/adapters/psqlpy/config.py +372 -203
- sqlspec/adapters/psqlpy/driver.py +197 -533
- sqlspec/adapters/psycopg/__init__.py +3 -8
- sqlspec/adapters/psycopg/config.py +725 -0
- sqlspec/adapters/psycopg/driver.py +734 -694
- sqlspec/adapters/sqlite/__init__.py +2 -6
- sqlspec/adapters/sqlite/config.py +146 -81
- sqlspec/adapters/sqlite/driver.py +242 -405
- sqlspec/base.py +220 -784
- sqlspec/config.py +354 -0
- sqlspec/driver/__init__.py +22 -0
- sqlspec/driver/_async.py +252 -0
- sqlspec/driver/_common.py +338 -0
- sqlspec/driver/_sync.py +261 -0
- sqlspec/driver/mixins/__init__.py +17 -0
- sqlspec/driver/mixins/_pipeline.py +523 -0
- sqlspec/driver/mixins/_result_utils.py +122 -0
- sqlspec/driver/mixins/_sql_translator.py +35 -0
- sqlspec/driver/mixins/_storage.py +993 -0
- sqlspec/driver/mixins/_type_coercion.py +131 -0
- sqlspec/exceptions.py +299 -7
- sqlspec/extensions/aiosql/__init__.py +10 -0
- sqlspec/extensions/aiosql/adapter.py +474 -0
- sqlspec/extensions/litestar/__init__.py +1 -6
- sqlspec/extensions/litestar/_utils.py +1 -5
- sqlspec/extensions/litestar/config.py +5 -6
- sqlspec/extensions/litestar/handlers.py +13 -12
- sqlspec/extensions/litestar/plugin.py +22 -24
- sqlspec/extensions/litestar/providers.py +37 -55
- sqlspec/loader.py +528 -0
- sqlspec/service/__init__.py +3 -0
- sqlspec/service/base.py +24 -0
- sqlspec/service/pagination.py +26 -0
- sqlspec/statement/__init__.py +21 -0
- sqlspec/statement/builder/__init__.py +54 -0
- sqlspec/statement/builder/_ddl_utils.py +119 -0
- sqlspec/statement/builder/_parsing_utils.py +135 -0
- sqlspec/statement/builder/base.py +328 -0
- sqlspec/statement/builder/ddl.py +1379 -0
- sqlspec/statement/builder/delete.py +80 -0
- sqlspec/statement/builder/insert.py +274 -0
- sqlspec/statement/builder/merge.py +95 -0
- sqlspec/statement/builder/mixins/__init__.py +65 -0
- sqlspec/statement/builder/mixins/_aggregate_functions.py +151 -0
- sqlspec/statement/builder/mixins/_case_builder.py +91 -0
- sqlspec/statement/builder/mixins/_common_table_expr.py +91 -0
- sqlspec/statement/builder/mixins/_delete_from.py +34 -0
- sqlspec/statement/builder/mixins/_from.py +61 -0
- sqlspec/statement/builder/mixins/_group_by.py +119 -0
- sqlspec/statement/builder/mixins/_having.py +35 -0
- sqlspec/statement/builder/mixins/_insert_from_select.py +48 -0
- sqlspec/statement/builder/mixins/_insert_into.py +36 -0
- sqlspec/statement/builder/mixins/_insert_values.py +69 -0
- sqlspec/statement/builder/mixins/_join.py +110 -0
- sqlspec/statement/builder/mixins/_limit_offset.py +53 -0
- sqlspec/statement/builder/mixins/_merge_clauses.py +405 -0
- sqlspec/statement/builder/mixins/_order_by.py +46 -0
- sqlspec/statement/builder/mixins/_pivot.py +82 -0
- sqlspec/statement/builder/mixins/_returning.py +37 -0
- sqlspec/statement/builder/mixins/_select_columns.py +60 -0
- sqlspec/statement/builder/mixins/_set_ops.py +122 -0
- sqlspec/statement/builder/mixins/_unpivot.py +80 -0
- sqlspec/statement/builder/mixins/_update_from.py +54 -0
- sqlspec/statement/builder/mixins/_update_set.py +91 -0
- sqlspec/statement/builder/mixins/_update_table.py +29 -0
- sqlspec/statement/builder/mixins/_where.py +374 -0
- sqlspec/statement/builder/mixins/_window_functions.py +86 -0
- sqlspec/statement/builder/protocols.py +20 -0
- sqlspec/statement/builder/select.py +206 -0
- sqlspec/statement/builder/update.py +178 -0
- sqlspec/statement/filters.py +571 -0
- sqlspec/statement/parameters.py +736 -0
- sqlspec/statement/pipelines/__init__.py +67 -0
- sqlspec/statement/pipelines/analyzers/__init__.py +9 -0
- sqlspec/statement/pipelines/analyzers/_analyzer.py +649 -0
- sqlspec/statement/pipelines/base.py +315 -0
- sqlspec/statement/pipelines/context.py +119 -0
- sqlspec/statement/pipelines/result_types.py +41 -0
- sqlspec/statement/pipelines/transformers/__init__.py +8 -0
- sqlspec/statement/pipelines/transformers/_expression_simplifier.py +256 -0
- sqlspec/statement/pipelines/transformers/_literal_parameterizer.py +623 -0
- sqlspec/statement/pipelines/transformers/_remove_comments.py +66 -0
- sqlspec/statement/pipelines/transformers/_remove_hints.py +81 -0
- sqlspec/statement/pipelines/validators/__init__.py +23 -0
- sqlspec/statement/pipelines/validators/_dml_safety.py +275 -0
- sqlspec/statement/pipelines/validators/_parameter_style.py +297 -0
- sqlspec/statement/pipelines/validators/_performance.py +703 -0
- sqlspec/statement/pipelines/validators/_security.py +990 -0
- sqlspec/statement/pipelines/validators/base.py +67 -0
- sqlspec/statement/result.py +527 -0
- sqlspec/statement/splitter.py +701 -0
- sqlspec/statement/sql.py +1198 -0
- sqlspec/storage/__init__.py +15 -0
- sqlspec/storage/backends/__init__.py +0 -0
- sqlspec/storage/backends/base.py +166 -0
- sqlspec/storage/backends/fsspec.py +315 -0
- sqlspec/storage/backends/obstore.py +464 -0
- sqlspec/storage/protocol.py +170 -0
- sqlspec/storage/registry.py +315 -0
- sqlspec/typing.py +157 -36
- sqlspec/utils/correlation.py +155 -0
- sqlspec/utils/deprecation.py +3 -6
- sqlspec/utils/fixtures.py +6 -11
- sqlspec/utils/logging.py +135 -0
- sqlspec/utils/module_loader.py +45 -43
- sqlspec/utils/serializers.py +4 -0
- sqlspec/utils/singleton.py +6 -8
- sqlspec/utils/sync_tools.py +15 -27
- sqlspec/utils/text.py +58 -26
- {sqlspec-0.11.1.dist-info → sqlspec-0.12.1.dist-info}/METADATA +97 -26
- sqlspec-0.12.1.dist-info/RECORD +145 -0
- sqlspec/adapters/bigquery/config/__init__.py +0 -3
- sqlspec/adapters/bigquery/config/_common.py +0 -40
- sqlspec/adapters/bigquery/config/_sync.py +0 -87
- sqlspec/adapters/oracledb/config/__init__.py +0 -9
- sqlspec/adapters/oracledb/config/_asyncio.py +0 -186
- sqlspec/adapters/oracledb/config/_common.py +0 -131
- sqlspec/adapters/oracledb/config/_sync.py +0 -186
- sqlspec/adapters/psycopg/config/__init__.py +0 -19
- sqlspec/adapters/psycopg/config/_async.py +0 -169
- sqlspec/adapters/psycopg/config/_common.py +0 -56
- sqlspec/adapters/psycopg/config/_sync.py +0 -168
- sqlspec/filters.py +0 -331
- sqlspec/mixins.py +0 -305
- sqlspec/statement.py +0 -378
- sqlspec-0.11.1.dist-info/RECORD +0 -69
- {sqlspec-0.11.1.dist-info → sqlspec-0.12.1.dist-info}/WHEEL +0 -0
- {sqlspec-0.11.1.dist-info → sqlspec-0.12.1.dist-info}/licenses/LICENSE +0 -0
- {sqlspec-0.11.1.dist-info → sqlspec-0.12.1.dist-info}/licenses/NOTICE +0 -0
sqlspec/_typing.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# ruff: noqa: RUF100, PLR0913, A002, DOC201, PLR6301
|
|
1
|
+
# ruff: noqa: RUF100, PLR0913, A002, DOC201, PLR6301, PLR0917, ARG004
|
|
2
2
|
"""This is a simple wrapper around a few important classes in each library.
|
|
3
3
|
|
|
4
4
|
This is used to ensure compatibility when one or more of the libraries are installed.
|
|
@@ -6,6 +6,7 @@ This is used to ensure compatibility when one or more of the libraries are insta
|
|
|
6
6
|
|
|
7
7
|
from collections.abc import Iterable, Mapping
|
|
8
8
|
from enum import Enum
|
|
9
|
+
from importlib.util import find_spec
|
|
9
10
|
from typing import Any, ClassVar, Final, Optional, Protocol, Union, cast, runtime_checkable
|
|
10
11
|
|
|
11
12
|
from typing_extensions import Literal, TypeVar, dataclass_transform
|
|
@@ -13,9 +14,13 @@ from typing_extensions import Literal, TypeVar, dataclass_transform
|
|
|
13
14
|
|
|
14
15
|
@runtime_checkable
|
|
15
16
|
class DataclassProtocol(Protocol):
|
|
16
|
-
"""Protocol for instance checking dataclasses.
|
|
17
|
+
"""Protocol for instance checking dataclasses.
|
|
17
18
|
|
|
18
|
-
__dataclass_fields__
|
|
19
|
+
This protocol only requires the presence of `__dataclass_fields__`, which is the
|
|
20
|
+
standard attribute that Python's dataclasses module adds to all dataclass instances.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
__dataclass_fields__: "ClassVar[dict[str, Any]]"
|
|
19
24
|
|
|
20
25
|
|
|
21
26
|
T = TypeVar("T")
|
|
@@ -32,19 +37,18 @@ try:
|
|
|
32
37
|
except ImportError:
|
|
33
38
|
from dataclasses import dataclass
|
|
34
39
|
|
|
35
|
-
@runtime_checkable
|
|
36
40
|
class BaseModel(Protocol): # type: ignore[no-redef]
|
|
37
41
|
"""Placeholder Implementation"""
|
|
38
42
|
|
|
39
|
-
model_fields: ClassVar[dict[str, Any]]
|
|
43
|
+
model_fields: "ClassVar[dict[str, Any]]"
|
|
40
44
|
|
|
41
45
|
def model_dump(
|
|
42
46
|
self,
|
|
43
47
|
/,
|
|
44
48
|
*,
|
|
45
|
-
include: Optional[Any] = None,
|
|
46
|
-
exclude: Optional[Any] = None,
|
|
47
|
-
context: Optional[Any] = None,
|
|
49
|
+
include: "Optional[Any]" = None,
|
|
50
|
+
exclude: "Optional[Any]" = None,
|
|
51
|
+
context: "Optional[Any]" = None,
|
|
48
52
|
by_alias: bool = False,
|
|
49
53
|
exclude_unset: bool = False,
|
|
50
54
|
exclude_defaults: bool = False,
|
|
@@ -60,9 +64,9 @@ except ImportError:
|
|
|
60
64
|
self,
|
|
61
65
|
/,
|
|
62
66
|
*,
|
|
63
|
-
include: Optional[Any] = None,
|
|
64
|
-
exclude: Optional[Any] = None,
|
|
65
|
-
context: Optional[Any] = None,
|
|
67
|
+
include: "Optional[Any]" = None,
|
|
68
|
+
exclude: "Optional[Any]" = None,
|
|
69
|
+
context: "Optional[Any]" = None,
|
|
66
70
|
by_alias: bool = False,
|
|
67
71
|
exclude_unset: bool = False,
|
|
68
72
|
exclude_defaults: bool = False,
|
|
@@ -82,9 +86,9 @@ except ImportError:
|
|
|
82
86
|
self,
|
|
83
87
|
type: Any, # noqa: A002
|
|
84
88
|
*,
|
|
85
|
-
config: Optional[Any] = None,
|
|
89
|
+
config: "Optional[Any]" = None,
|
|
86
90
|
_parent_depth: int = 2,
|
|
87
|
-
module: Optional[str] = None,
|
|
91
|
+
module: "Optional[str]" = None,
|
|
88
92
|
) -> None:
|
|
89
93
|
"""Init"""
|
|
90
94
|
|
|
@@ -93,10 +97,10 @@ except ImportError:
|
|
|
93
97
|
object: Any,
|
|
94
98
|
/,
|
|
95
99
|
*,
|
|
96
|
-
strict: Optional[bool] = None,
|
|
97
|
-
from_attributes: Optional[bool] = None,
|
|
98
|
-
context: Optional[dict[str, Any]] = None,
|
|
99
|
-
experimental_allow_partial: Union[bool, Literal[
|
|
100
|
+
strict: "Optional[bool]" = None,
|
|
101
|
+
from_attributes: "Optional[bool]" = None,
|
|
102
|
+
context: "Optional[dict[str, Any]]" = None,
|
|
103
|
+
experimental_allow_partial: "Union[bool, Literal['off', 'on', 'trailing-strings']]" = False,
|
|
100
104
|
) -> "T_co":
|
|
101
105
|
"""Stub"""
|
|
102
106
|
return cast("T_co", object)
|
|
@@ -128,16 +132,16 @@ except ImportError:
|
|
|
128
132
|
class Struct(Protocol): # type: ignore[no-redef]
|
|
129
133
|
"""Placeholder Implementation"""
|
|
130
134
|
|
|
131
|
-
__struct_fields__: ClassVar[tuple[str, ...]]
|
|
135
|
+
__struct_fields__: "ClassVar[tuple[str, ...]]"
|
|
132
136
|
|
|
133
137
|
def convert( # type: ignore[no-redef]
|
|
134
138
|
obj: Any,
|
|
135
|
-
type: Union[Any, type[T]], # noqa: A002
|
|
139
|
+
type: "Union[Any, type[T]]", # noqa: A002
|
|
136
140
|
*,
|
|
137
141
|
strict: bool = True,
|
|
138
142
|
from_attributes: bool = False,
|
|
139
|
-
dec_hook: Optional[Callable[[type, Any], Any]] = None,
|
|
140
|
-
builtin_types: Optional[Iterable[type]] = None,
|
|
143
|
+
dec_hook: "Optional[Callable[[type, Any], Any]]" = None,
|
|
144
|
+
builtin_types: "Optional[Iterable[type]]" = None,
|
|
141
145
|
str_keys: bool = False,
|
|
142
146
|
) -> "Union[T, Any]":
|
|
143
147
|
"""Placeholder implementation"""
|
|
@@ -188,55 +192,353 @@ EmptyType = Union[Literal[EmptyEnum.EMPTY], UnsetType]
|
|
|
188
192
|
Empty: Final = EmptyEnum.EMPTY
|
|
189
193
|
|
|
190
194
|
|
|
195
|
+
@runtime_checkable
|
|
196
|
+
class ArrowTableResult(Protocol):
|
|
197
|
+
"""This is a typed shim for pyarrow.Table."""
|
|
198
|
+
|
|
199
|
+
def to_batches(self, batch_size: int) -> Any:
|
|
200
|
+
return None
|
|
201
|
+
|
|
202
|
+
@property
|
|
203
|
+
def num_rows(self) -> int:
|
|
204
|
+
return 0
|
|
205
|
+
|
|
206
|
+
@property
|
|
207
|
+
def num_columns(self) -> int:
|
|
208
|
+
return 0
|
|
209
|
+
|
|
210
|
+
def to_pydict(self) -> dict[str, Any]:
|
|
211
|
+
return {}
|
|
212
|
+
|
|
213
|
+
def to_string(self) -> str:
|
|
214
|
+
return ""
|
|
215
|
+
|
|
216
|
+
def from_arrays(
|
|
217
|
+
self,
|
|
218
|
+
arrays: list[Any],
|
|
219
|
+
names: "Optional[list[str]]" = None,
|
|
220
|
+
schema: "Optional[Any]" = None,
|
|
221
|
+
metadata: "Optional[Mapping[str, Any]]" = None,
|
|
222
|
+
) -> Any:
|
|
223
|
+
return None
|
|
224
|
+
|
|
225
|
+
def from_pydict(
|
|
226
|
+
self, mapping: dict[str, Any], schema: "Optional[Any]" = None, metadata: "Optional[Mapping[str, Any]]" = None
|
|
227
|
+
) -> Any:
|
|
228
|
+
return None
|
|
229
|
+
|
|
230
|
+
def from_batches(self, batches: Iterable[Any], schema: Optional[Any] = None) -> Any:
|
|
231
|
+
return None
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
@runtime_checkable
|
|
235
|
+
class ArrowRecordBatchResult(Protocol):
|
|
236
|
+
"""This is a typed shim for pyarrow.RecordBatch."""
|
|
237
|
+
|
|
238
|
+
def num_rows(self) -> int:
|
|
239
|
+
return 0
|
|
240
|
+
|
|
241
|
+
def num_columns(self) -> int:
|
|
242
|
+
return 0
|
|
243
|
+
|
|
244
|
+
def to_pydict(self) -> dict[str, Any]:
|
|
245
|
+
return {}
|
|
246
|
+
|
|
247
|
+
def to_pandas(self) -> Any:
|
|
248
|
+
return None
|
|
249
|
+
|
|
250
|
+
def schema(self) -> Any:
|
|
251
|
+
return None
|
|
252
|
+
|
|
253
|
+
def column(self, i: int) -> Any:
|
|
254
|
+
return None
|
|
255
|
+
|
|
256
|
+
def slice(self, offset: int = 0, length: "Optional[int]" = None) -> Any:
|
|
257
|
+
return None
|
|
258
|
+
|
|
259
|
+
|
|
191
260
|
try:
|
|
261
|
+
from pyarrow import RecordBatch as ArrowRecordBatch
|
|
192
262
|
from pyarrow import Table as ArrowTable
|
|
193
263
|
|
|
194
264
|
PYARROW_INSTALLED = True
|
|
195
265
|
except ImportError:
|
|
266
|
+
ArrowTable = ArrowTableResult # type: ignore[assignment,misc]
|
|
267
|
+
ArrowRecordBatch = ArrowRecordBatchResult # type: ignore[assignment,misc]
|
|
196
268
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
269
|
+
PYARROW_INSTALLED = False # pyright: ignore[reportConstantRedefinition]
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
try:
|
|
273
|
+
from opentelemetry import trace # pyright: ignore[reportMissingImports, reportAssignmentType]
|
|
274
|
+
from opentelemetry.trace import ( # pyright: ignore[reportMissingImports, reportAssignmentType]
|
|
275
|
+
Span, # pyright: ignore[reportMissingImports, reportAssignmentType]
|
|
276
|
+
Status,
|
|
277
|
+
StatusCode,
|
|
278
|
+
Tracer, # pyright: ignore[reportMissingImports, reportAssignmentType]
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
OPENTELEMETRY_INSTALLED = True
|
|
282
|
+
except ImportError:
|
|
283
|
+
# Define shims for when opentelemetry is not installed
|
|
284
|
+
|
|
285
|
+
class Span: # type: ignore[no-redef]
|
|
286
|
+
def set_attribute(self, key: str, value: Any) -> None:
|
|
287
|
+
return None
|
|
200
288
|
|
|
201
|
-
def
|
|
202
|
-
def num_rows(self) -> int: ...
|
|
203
|
-
def num_columns(self) -> int: ...
|
|
204
|
-
def to_pydict(self) -> dict[str, Any]: ...
|
|
205
|
-
def to_string(self) -> str: ...
|
|
206
|
-
def from_arrays(
|
|
289
|
+
def record_exception(
|
|
207
290
|
self,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
) ->
|
|
213
|
-
|
|
291
|
+
exception: "Exception",
|
|
292
|
+
attributes: "Optional[Mapping[str, Any]]" = None,
|
|
293
|
+
timestamp: "Optional[int]" = None,
|
|
294
|
+
escaped: bool = False,
|
|
295
|
+
) -> None:
|
|
296
|
+
return None
|
|
297
|
+
|
|
298
|
+
def set_status(self, status: Any, description: "Optional[str]" = None) -> None:
|
|
299
|
+
return None
|
|
300
|
+
|
|
301
|
+
def end(self, end_time: "Optional[int]" = None) -> None:
|
|
302
|
+
return None
|
|
303
|
+
|
|
304
|
+
def __enter__(self) -> "Span":
|
|
305
|
+
return self # type: ignore[return-value]
|
|
306
|
+
|
|
307
|
+
def __exit__(self, exc_type: object, exc_val: object, exc_tb: object) -> None:
|
|
308
|
+
return None
|
|
309
|
+
|
|
310
|
+
class Tracer: # type: ignore[no-redef]
|
|
311
|
+
def start_span(
|
|
214
312
|
self,
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
313
|
+
name: str,
|
|
314
|
+
context: Any = None,
|
|
315
|
+
kind: Any = None,
|
|
316
|
+
attributes: Any = None,
|
|
317
|
+
links: Any = None,
|
|
318
|
+
start_time: Any = None,
|
|
319
|
+
record_exception: bool = True,
|
|
320
|
+
set_status_on_exception: bool = True,
|
|
321
|
+
) -> Span:
|
|
322
|
+
return Span() # type: ignore[abstract]
|
|
323
|
+
|
|
324
|
+
class _TraceModule:
|
|
325
|
+
def get_tracer(
|
|
326
|
+
self,
|
|
327
|
+
instrumenting_module_name: str,
|
|
328
|
+
instrumenting_library_version: "Optional[str]" = None,
|
|
329
|
+
schema_url: "Optional[str]" = None,
|
|
330
|
+
tracer_provider: Any = None,
|
|
331
|
+
) -> Tracer:
|
|
332
|
+
return Tracer() # type: ignore[abstract] # pragma: no cover
|
|
333
|
+
|
|
334
|
+
TracerProvider = type(None) # Shim for TracerProvider if needed elsewhere
|
|
335
|
+
StatusCode = type(None) # Shim for StatusCode
|
|
336
|
+
Status = type(None) # Shim for Status
|
|
337
|
+
|
|
338
|
+
trace = _TraceModule() # type: ignore[assignment]
|
|
339
|
+
StatusCode = trace.StatusCode # type: ignore[misc]
|
|
340
|
+
Status = trace.Status # type: ignore[misc]
|
|
341
|
+
OPENTELEMETRY_INSTALLED = False # pyright: ignore[reportConstantRedefinition]
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
try:
|
|
345
|
+
from prometheus_client import ( # pyright: ignore[reportMissingImports, reportAssignmentType]
|
|
346
|
+
Counter, # pyright: ignore[reportAssignmentType]
|
|
347
|
+
Gauge, # pyright: ignore[reportAssignmentType]
|
|
348
|
+
Histogram, # pyright: ignore[reportAssignmentType]
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
PROMETHEUS_INSTALLED = True
|
|
352
|
+
except ImportError:
|
|
353
|
+
# Define shims for when prometheus_client is not installed
|
|
354
|
+
|
|
355
|
+
class _Metric: # Base shim for metrics
|
|
356
|
+
def __init__(
|
|
357
|
+
self,
|
|
358
|
+
name: str,
|
|
359
|
+
documentation: str,
|
|
360
|
+
labelnames: tuple[str, ...] = (),
|
|
361
|
+
namespace: str = "",
|
|
362
|
+
subsystem: str = "",
|
|
363
|
+
unit: str = "",
|
|
364
|
+
registry: Any = None,
|
|
365
|
+
ejemplar_fn: Any = None,
|
|
366
|
+
) -> None:
|
|
367
|
+
return None
|
|
368
|
+
|
|
369
|
+
def labels(self, *labelvalues: str, **labelkwargs: str) -> "_MetricInstance":
|
|
370
|
+
return _MetricInstance()
|
|
371
|
+
|
|
372
|
+
class _MetricInstance:
|
|
373
|
+
def inc(self, amount: float = 1) -> None:
|
|
374
|
+
return None
|
|
375
|
+
|
|
376
|
+
def dec(self, amount: float = 1) -> None:
|
|
377
|
+
return None
|
|
378
|
+
|
|
379
|
+
def set(self, value: float) -> None:
|
|
380
|
+
return None
|
|
381
|
+
|
|
382
|
+
def observe(self, amount: float) -> None:
|
|
383
|
+
return None
|
|
384
|
+
|
|
385
|
+
class Counter(_Metric): # type: ignore[no-redef]
|
|
386
|
+
def labels(self, *labelvalues: str, **labelkwargs: str) -> _MetricInstance:
|
|
387
|
+
return _MetricInstance() # pragma: no cover
|
|
388
|
+
|
|
389
|
+
class Gauge(_Metric): # type: ignore[no-redef]
|
|
390
|
+
def labels(self, *labelvalues: str, **labelkwargs: str) -> _MetricInstance:
|
|
391
|
+
return _MetricInstance() # pragma: no cover
|
|
392
|
+
|
|
393
|
+
class Histogram(_Metric): # type: ignore[no-redef]
|
|
394
|
+
def labels(self, *labelvalues: str, **labelkwargs: str) -> _MetricInstance:
|
|
395
|
+
return _MetricInstance() # pragma: no cover
|
|
396
|
+
|
|
397
|
+
PROMETHEUS_INSTALLED = False # pyright: ignore[reportConstantRedefinition]
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
try:
|
|
401
|
+
import aiosql # pyright: ignore[reportMissingImports, reportAssignmentType]
|
|
402
|
+
from aiosql.types import ( # pyright: ignore[reportMissingImports, reportAssignmentType]
|
|
403
|
+
AsyncDriverAdapterProtocol as AiosqlAsyncProtocol, # pyright: ignore[reportMissingImports, reportAssignmentType]
|
|
404
|
+
)
|
|
405
|
+
from aiosql.types import ( # pyright: ignore[reportMissingImports, reportAssignmentType]
|
|
406
|
+
DriverAdapterProtocol as AiosqlProtocol, # pyright: ignore[reportMissingImports, reportAssignmentType]
|
|
407
|
+
)
|
|
408
|
+
from aiosql.types import ParamType as AiosqlParamType # pyright: ignore[reportMissingImports, reportAssignmentType]
|
|
409
|
+
from aiosql.types import (
|
|
410
|
+
SQLOperationType as AiosqlSQLOperationType, # pyright: ignore[reportMissingImports, reportAssignmentType]
|
|
411
|
+
)
|
|
412
|
+
from aiosql.types import ( # pyright: ignore[reportMissingImports, reportAssignmentType]
|
|
413
|
+
SyncDriverAdapterProtocol as AiosqlSyncProtocol, # pyright: ignore[reportMissingImports, reportAssignmentType]
|
|
414
|
+
)
|
|
415
|
+
|
|
416
|
+
AIOSQL_INSTALLED = True
|
|
417
|
+
except ImportError:
|
|
418
|
+
# Define shims for when aiosql is not installed
|
|
419
|
+
|
|
420
|
+
class _AiosqlShim:
|
|
421
|
+
"""Placeholder aiosql module"""
|
|
422
|
+
|
|
423
|
+
@staticmethod
|
|
424
|
+
def from_path(sql_path: str, driver_adapter: Any, **kwargs: Any) -> Any:
|
|
425
|
+
"""Placeholder from_path method"""
|
|
426
|
+
return None # pragma: no cover
|
|
427
|
+
|
|
428
|
+
@staticmethod
|
|
429
|
+
def from_str(sql_str: str, driver_adapter: Any, **kwargs: Any) -> Any:
|
|
430
|
+
"""Placeholder from_str method"""
|
|
431
|
+
return None # pragma: no cover
|
|
432
|
+
|
|
433
|
+
aiosql = _AiosqlShim() # type: ignore[assignment]
|
|
434
|
+
|
|
435
|
+
# Placeholder types for aiosql protocols
|
|
436
|
+
AiosqlParamType = Union[dict[str, Any], list[Any], tuple[Any, ...], None] # type: ignore[misc]
|
|
437
|
+
|
|
438
|
+
class AiosqlSQLOperationType(Enum): # type: ignore[no-redef]
|
|
439
|
+
"""Enumeration of aiosql operation types."""
|
|
440
|
+
|
|
441
|
+
INSERT_RETURNING = 0
|
|
442
|
+
INSERT_UPDATE_DELETE = 1
|
|
443
|
+
INSERT_UPDATE_DELETE_MANY = 2
|
|
444
|
+
SCRIPT = 3
|
|
445
|
+
SELECT = 4
|
|
446
|
+
SELECT_ONE = 5
|
|
447
|
+
SELECT_VALUE = 6
|
|
448
|
+
|
|
449
|
+
@runtime_checkable
|
|
450
|
+
class AiosqlProtocol(Protocol): # type: ignore[no-redef]
|
|
451
|
+
"""Placeholder for aiosql DriverAdapterProtocol"""
|
|
452
|
+
|
|
453
|
+
def process_sql(self, query_name: str, op_type: Any, sql: str) -> str: ...
|
|
454
|
+
|
|
455
|
+
@runtime_checkable
|
|
456
|
+
class AiosqlSyncProtocol(Protocol): # type: ignore[no-redef]
|
|
457
|
+
"""Placeholder for aiosql SyncDriverAdapterProtocol"""
|
|
458
|
+
|
|
459
|
+
is_aio_driver: "ClassVar[bool]"
|
|
460
|
+
|
|
461
|
+
def process_sql(self, query_name: str, op_type: Any, sql: str) -> str: ...
|
|
462
|
+
def select(
|
|
463
|
+
self, conn: Any, query_name: str, sql: str, parameters: Any, record_class: "Optional[Any]" = None
|
|
218
464
|
) -> Any: ...
|
|
219
|
-
def
|
|
465
|
+
def select_one(
|
|
466
|
+
self, conn: Any, query_name: str, sql: str, parameters: Any, record_class: "Optional[Any]" = None
|
|
467
|
+
) -> "Optional[Any]": ...
|
|
468
|
+
def select_value(self, conn: Any, query_name: str, sql: str, parameters: Any) -> "Optional[Any]": ...
|
|
469
|
+
def select_cursor(self, conn: Any, query_name: str, sql: str, parameters: Any) -> Any: ...
|
|
470
|
+
def insert_update_delete(self, conn: Any, query_name: str, sql: str, parameters: Any) -> int: ...
|
|
471
|
+
def insert_update_delete_many(self, conn: Any, query_name: str, sql: str, parameters: Any) -> int: ...
|
|
472
|
+
def insert_returning(self, conn: Any, query_name: str, sql: str, parameters: Any) -> "Optional[Any]": ...
|
|
220
473
|
|
|
221
|
-
|
|
474
|
+
@runtime_checkable
|
|
475
|
+
class AiosqlAsyncProtocol(Protocol): # type: ignore[no-redef]
|
|
476
|
+
"""Placeholder for aiosql AsyncDriverAdapterProtocol"""
|
|
477
|
+
|
|
478
|
+
is_aio_driver: "ClassVar[bool]"
|
|
479
|
+
|
|
480
|
+
def process_sql(self, query_name: str, op_type: Any, sql: str) -> str: ...
|
|
481
|
+
async def select(
|
|
482
|
+
self, conn: Any, query_name: str, sql: str, parameters: Any, record_class: "Optional[Any]" = None
|
|
483
|
+
) -> Any: ...
|
|
484
|
+
async def select_one(
|
|
485
|
+
self, conn: Any, query_name: str, sql: str, parameters: Any, record_class: "Optional[Any]" = None
|
|
486
|
+
) -> "Optional[Any]": ...
|
|
487
|
+
async def select_value(self, conn: Any, query_name: str, sql: str, parameters: Any) -> "Optional[Any]": ...
|
|
488
|
+
async def select_cursor(self, conn: Any, query_name: str, sql: str, parameters: Any) -> Any: ...
|
|
489
|
+
async def insert_update_delete(self, conn: Any, query_name: str, sql: str, parameters: Any) -> None: ...
|
|
490
|
+
async def insert_update_delete_many(self, conn: Any, query_name: str, sql: str, parameters: Any) -> None: ...
|
|
491
|
+
async def insert_returning(self, conn: Any, query_name: str, sql: str, parameters: Any) -> "Optional[Any]": ...
|
|
492
|
+
|
|
493
|
+
AIOSQL_INSTALLED = False # pyright: ignore[reportConstantRedefinition]
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
FSSPEC_INSTALLED = bool(find_spec("fsspec"))
|
|
497
|
+
OBSTORE_INSTALLED = bool(find_spec("obstore"))
|
|
498
|
+
PGVECTOR_INSTALLED = bool(find_spec("pgvector"))
|
|
222
499
|
|
|
223
500
|
|
|
224
501
|
__all__ = (
|
|
502
|
+
"AIOSQL_INSTALLED",
|
|
503
|
+
"FSSPEC_INSTALLED",
|
|
225
504
|
"LITESTAR_INSTALLED",
|
|
226
505
|
"MSGSPEC_INSTALLED",
|
|
506
|
+
"OBSTORE_INSTALLED",
|
|
507
|
+
"OPENTELEMETRY_INSTALLED",
|
|
508
|
+
"PGVECTOR_INSTALLED",
|
|
509
|
+
"PROMETHEUS_INSTALLED",
|
|
227
510
|
"PYARROW_INSTALLED",
|
|
228
511
|
"PYDANTIC_INSTALLED",
|
|
229
512
|
"UNSET",
|
|
513
|
+
"AiosqlAsyncProtocol",
|
|
514
|
+
"AiosqlParamType",
|
|
515
|
+
"AiosqlProtocol",
|
|
516
|
+
"AiosqlSQLOperationType",
|
|
517
|
+
"AiosqlSyncProtocol",
|
|
518
|
+
"ArrowRecordBatch",
|
|
519
|
+
"ArrowRecordBatchResult",
|
|
230
520
|
"ArrowTable",
|
|
521
|
+
"ArrowTableResult",
|
|
231
522
|
"BaseModel",
|
|
523
|
+
"Counter",
|
|
232
524
|
"DTOData",
|
|
233
525
|
"DataclassProtocol",
|
|
234
526
|
"Empty",
|
|
235
527
|
"EmptyEnum",
|
|
236
528
|
"EmptyType",
|
|
237
529
|
"FailFast",
|
|
530
|
+
"Gauge",
|
|
531
|
+
"Histogram",
|
|
532
|
+
"Span",
|
|
533
|
+
"Status",
|
|
534
|
+
"StatusCode",
|
|
238
535
|
"Struct",
|
|
536
|
+
"T",
|
|
537
|
+
"T_co",
|
|
538
|
+
"Tracer",
|
|
239
539
|
"TypeAdapter",
|
|
240
540
|
"UnsetType",
|
|
541
|
+
"aiosql",
|
|
241
542
|
"convert",
|
|
543
|
+
"trace",
|
|
242
544
|
)
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
from sqlspec.adapters.adbc.config import AdbcConfig
|
|
1
|
+
from sqlspec.adapters.adbc.config import CONNECTION_FIELDS, AdbcConfig
|
|
2
2
|
from sqlspec.adapters.adbc.driver import AdbcConnection, AdbcDriver
|
|
3
3
|
|
|
4
|
-
__all__ = (
|
|
5
|
-
"AdbcConfig",
|
|
6
|
-
"AdbcConnection",
|
|
7
|
-
"AdbcDriver",
|
|
8
|
-
)
|
|
4
|
+
__all__ = ("CONNECTION_FIELDS", "AdbcConfig", "AdbcConnection", "AdbcDriver")
|