sqlspec 0.11.0__py3-none-any.whl → 0.12.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 +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 -644
- sqlspec/adapters/aiosqlite/__init__.py +2 -6
- sqlspec/adapters/aiosqlite/config.py +143 -57
- sqlspec/adapters/aiosqlite/driver.py +269 -462
- sqlspec/adapters/asyncmy/__init__.py +3 -8
- sqlspec/adapters/asyncmy/config.py +247 -202
- sqlspec/adapters/asyncmy/driver.py +217 -451
- sqlspec/adapters/asyncpg/__init__.py +4 -7
- sqlspec/adapters/asyncpg/config.py +329 -176
- sqlspec/adapters/asyncpg/driver.py +418 -498
- sqlspec/adapters/bigquery/__init__.py +2 -2
- sqlspec/adapters/bigquery/config.py +407 -0
- sqlspec/adapters/bigquery/driver.py +592 -634
- sqlspec/adapters/duckdb/__init__.py +4 -1
- sqlspec/adapters/duckdb/config.py +432 -321
- sqlspec/adapters/duckdb/driver.py +393 -436
- sqlspec/adapters/oracledb/__init__.py +3 -8
- sqlspec/adapters/oracledb/config.py +625 -0
- sqlspec/adapters/oracledb/driver.py +549 -942
- sqlspec/adapters/psqlpy/__init__.py +4 -7
- sqlspec/adapters/psqlpy/config.py +372 -203
- sqlspec/adapters/psqlpy/driver.py +197 -550
- sqlspec/adapters/psycopg/__init__.py +3 -8
- sqlspec/adapters/psycopg/config.py +741 -0
- sqlspec/adapters/psycopg/driver.py +732 -733
- sqlspec/adapters/sqlite/__init__.py +2 -6
- sqlspec/adapters/sqlite/config.py +146 -81
- sqlspec/adapters/sqlite/driver.py +243 -426
- sqlspec/base.py +220 -825
- 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.0.dist-info → sqlspec-0.12.0.dist-info}/METADATA +100 -26
- sqlspec-0.12.0.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 -330
- sqlspec/mixins.py +0 -306
- sqlspec/statement.py +0 -378
- sqlspec-0.11.0.dist-info/RECORD +0 -69
- {sqlspec-0.11.0.dist-info → sqlspec-0.12.0.dist-info}/WHEEL +0 -0
- {sqlspec-0.11.0.dist-info → sqlspec-0.12.0.dist-info}/licenses/LICENSE +0 -0
- {sqlspec-0.11.0.dist-info → sqlspec-0.12.0.dist-info}/licenses/NOTICE +0 -0
|
@@ -3,31 +3,26 @@ from typing import TYPE_CHECKING, Any, Union
|
|
|
3
3
|
from litestar.di import Provide
|
|
4
4
|
from litestar.plugins import InitPluginProtocol
|
|
5
5
|
|
|
6
|
-
from sqlspec.base import (
|
|
7
|
-
AsyncConfigT,
|
|
8
|
-
DatabaseConfigProtocol,
|
|
9
|
-
DriverT,
|
|
10
|
-
SyncConfigT,
|
|
11
|
-
)
|
|
12
6
|
from sqlspec.base import SQLSpec as SQLSpecBase
|
|
7
|
+
from sqlspec.config import AsyncConfigT, DatabaseConfigProtocol, DriverT, SyncConfigT
|
|
13
8
|
from sqlspec.exceptions import ImproperConfigurationError
|
|
14
9
|
from sqlspec.extensions.litestar.config import DatabaseConfig
|
|
15
10
|
from sqlspec.typing import ConnectionT, PoolT
|
|
11
|
+
from sqlspec.utils.logging import get_logger
|
|
16
12
|
|
|
17
13
|
if TYPE_CHECKING:
|
|
18
14
|
from click import Group
|
|
19
15
|
from litestar.config.app import AppConfig
|
|
20
16
|
|
|
17
|
+
logger = get_logger("extensions.litestar")
|
|
18
|
+
|
|
21
19
|
|
|
22
20
|
class SQLSpec(InitPluginProtocol, SQLSpecBase):
|
|
23
21
|
"""SQLSpec plugin."""
|
|
24
22
|
|
|
25
23
|
__slots__ = ("_config", "_plugin_configs")
|
|
26
24
|
|
|
27
|
-
def __init__(
|
|
28
|
-
self,
|
|
29
|
-
config: Union["SyncConfigT", "AsyncConfigT", "DatabaseConfig", list["DatabaseConfig"]],
|
|
30
|
-
) -> None:
|
|
25
|
+
def __init__(self, config: Union["SyncConfigT", "AsyncConfigT", "DatabaseConfig", list["DatabaseConfig"]]) -> None:
|
|
31
26
|
"""Initialize ``SQLSpecPlugin``.
|
|
32
27
|
|
|
33
28
|
Args:
|
|
@@ -62,32 +57,32 @@ class SQLSpec(InitPluginProtocol, SQLSpecBase):
|
|
|
62
57
|
Returns:
|
|
63
58
|
The updated :class:`AppConfig <.config.app.AppConfig>` instance.
|
|
64
59
|
"""
|
|
60
|
+
|
|
65
61
|
self._validate_dependency_keys()
|
|
66
62
|
|
|
67
63
|
def store_sqlspec_in_state() -> None:
|
|
68
64
|
app_config.state.sqlspec = self
|
|
69
65
|
|
|
70
66
|
app_config.on_startup.append(store_sqlspec_in_state)
|
|
71
|
-
|
|
72
67
|
# Register types for injection
|
|
73
68
|
app_config.signature_types.extend(
|
|
74
|
-
[
|
|
75
|
-
SQLSpec,
|
|
76
|
-
ConnectionT,
|
|
77
|
-
PoolT,
|
|
78
|
-
DriverT,
|
|
79
|
-
DatabaseConfig,
|
|
80
|
-
DatabaseConfigProtocol,
|
|
81
|
-
SyncConfigT,
|
|
82
|
-
AsyncConfigT,
|
|
83
|
-
]
|
|
69
|
+
[SQLSpec, ConnectionT, PoolT, DriverT, DatabaseConfig, DatabaseConfigProtocol, SyncConfigT, AsyncConfigT]
|
|
84
70
|
)
|
|
85
71
|
|
|
72
|
+
# Create signature namespace for connection types
|
|
73
|
+
signature_namespace = {}
|
|
74
|
+
|
|
86
75
|
for c in self._plugin_configs:
|
|
87
76
|
c.annotation = self.add_config(c.config)
|
|
88
77
|
app_config.signature_types.append(c.annotation)
|
|
89
78
|
app_config.signature_types.append(c.config.connection_type) # type: ignore[union-attr]
|
|
90
79
|
app_config.signature_types.append(c.config.driver_type) # type: ignore[union-attr]
|
|
80
|
+
|
|
81
|
+
# Get signature namespace from the config
|
|
82
|
+
if hasattr(c.config, "get_signature_namespace"):
|
|
83
|
+
config_namespace = c.config.get_signature_namespace() # type: ignore[attr-defined]
|
|
84
|
+
signature_namespace.update(config_namespace)
|
|
85
|
+
|
|
91
86
|
app_config.before_send.append(c.before_send_handler)
|
|
92
87
|
app_config.lifespan.append(c.lifespan_handler) # pyright: ignore[reportUnknownMemberType]
|
|
93
88
|
app_config.dependencies.update(
|
|
@@ -95,9 +90,13 @@ class SQLSpec(InitPluginProtocol, SQLSpecBase):
|
|
|
95
90
|
c.connection_key: Provide(c.connection_provider),
|
|
96
91
|
c.pool_key: Provide(c.pool_provider),
|
|
97
92
|
c.session_key: Provide(c.session_provider),
|
|
98
|
-
}
|
|
93
|
+
}
|
|
99
94
|
)
|
|
100
95
|
|
|
96
|
+
# Update app config with signature namespace
|
|
97
|
+
if signature_namespace:
|
|
98
|
+
app_config.signature_namespace.update(signature_namespace)
|
|
99
|
+
|
|
101
100
|
return app_config
|
|
102
101
|
|
|
103
102
|
def get_annotations(self) -> "list[type[Union[SyncConfigT, AsyncConfigT]]]": # pyright: ignore[reportInvalidTypeVarUse]
|
|
@@ -109,8 +108,7 @@ class SQLSpec(InitPluginProtocol, SQLSpecBase):
|
|
|
109
108
|
return [c.annotation for c in self.config]
|
|
110
109
|
|
|
111
110
|
def get_annotation(
|
|
112
|
-
self,
|
|
113
|
-
key: "Union[str, SyncConfigT, AsyncConfigT, type[Union[SyncConfigT, AsyncConfigT]]]",
|
|
111
|
+
self, key: "Union[str, SyncConfigT, AsyncConfigT, type[Union[SyncConfigT, AsyncConfigT]]]"
|
|
114
112
|
) -> "type[Union[SyncConfigT, AsyncConfigT]]":
|
|
115
113
|
"""Return the annotation for the given configuration.
|
|
116
114
|
|
|
@@ -9,28 +9,20 @@ You should not have modify this module very often and should only be invoked und
|
|
|
9
9
|
import datetime
|
|
10
10
|
import inspect
|
|
11
11
|
from collections.abc import Callable
|
|
12
|
-
from typing import
|
|
13
|
-
Any,
|
|
14
|
-
Literal,
|
|
15
|
-
NamedTuple,
|
|
16
|
-
Optional,
|
|
17
|
-
TypedDict,
|
|
18
|
-
Union,
|
|
19
|
-
cast,
|
|
20
|
-
)
|
|
12
|
+
from typing import Any, Literal, NamedTuple, Optional, TypedDict, Union, cast
|
|
21
13
|
from uuid import UUID
|
|
22
14
|
|
|
23
15
|
from litestar.di import Provide
|
|
24
16
|
from litestar.params import Dependency, Parameter
|
|
25
17
|
from typing_extensions import NotRequired
|
|
26
18
|
|
|
27
|
-
from sqlspec.filters import (
|
|
28
|
-
|
|
29
|
-
CollectionFilter,
|
|
19
|
+
from sqlspec.statement.filters import (
|
|
20
|
+
BeforeAfterFilter,
|
|
30
21
|
FilterTypes,
|
|
31
|
-
|
|
22
|
+
InCollectionFilter,
|
|
23
|
+
LimitOffsetFilter,
|
|
32
24
|
NotInCollectionFilter,
|
|
33
|
-
|
|
25
|
+
OrderByFilter,
|
|
34
26
|
SearchFilter,
|
|
35
27
|
)
|
|
36
28
|
from sqlspec.utils.singleton import SingletonMeta
|
|
@@ -214,8 +206,8 @@ def _create_statement_filters(
|
|
|
214
206
|
|
|
215
207
|
def provide_id_filter( # pyright: ignore[reportUnknownParameterType]
|
|
216
208
|
ids: Optional[list[str]] = Parameter(query="ids", default=None, required=False),
|
|
217
|
-
) ->
|
|
218
|
-
return
|
|
209
|
+
) -> InCollectionFilter: # pyright: ignore[reportMissingTypeArgument]
|
|
210
|
+
return InCollectionFilter(field_name=config.get("id_field", "id"), values=ids)
|
|
219
211
|
|
|
220
212
|
filters[dep_defaults.ID_FILTER_DEPENDENCY_KEY] = Provide(provide_id_filter, sync_to_thread=False) # pyright: ignore[reportUnknownArgumentType]
|
|
221
213
|
|
|
@@ -224,8 +216,8 @@ def _create_statement_filters(
|
|
|
224
216
|
def provide_created_filter(
|
|
225
217
|
before: DTorNone = Parameter(query="createdBefore", default=None, required=False),
|
|
226
218
|
after: DTorNone = Parameter(query="createdAfter", default=None, required=False),
|
|
227
|
-
) ->
|
|
228
|
-
return
|
|
219
|
+
) -> BeforeAfterFilter:
|
|
220
|
+
return BeforeAfterFilter("created_at", before, after)
|
|
229
221
|
|
|
230
222
|
filters[dep_defaults.CREATED_FILTER_DEPENDENCY_KEY] = Provide(provide_created_filter, sync_to_thread=False)
|
|
231
223
|
|
|
@@ -234,8 +226,8 @@ def _create_statement_filters(
|
|
|
234
226
|
def provide_updated_filter(
|
|
235
227
|
before: DTorNone = Parameter(query="updatedBefore", default=None, required=False),
|
|
236
228
|
after: DTorNone = Parameter(query="updatedAfter", default=None, required=False),
|
|
237
|
-
) ->
|
|
238
|
-
return
|
|
229
|
+
) -> BeforeAfterFilter:
|
|
230
|
+
return BeforeAfterFilter("updated_at", before, after)
|
|
239
231
|
|
|
240
232
|
filters[dep_defaults.UPDATED_FILTER_DEPENDENCY_KEY] = Provide(provide_updated_filter, sync_to_thread=False)
|
|
241
233
|
|
|
@@ -249,8 +241,8 @@ def _create_statement_filters(
|
|
|
249
241
|
default=config.get("pagination_size", dep_defaults.DEFAULT_PAGINATION_SIZE),
|
|
250
242
|
required=False,
|
|
251
243
|
),
|
|
252
|
-
) ->
|
|
253
|
-
return
|
|
244
|
+
) -> LimitOffsetFilter:
|
|
245
|
+
return LimitOffsetFilter(page_size, page_size * (current_page - 1))
|
|
254
246
|
|
|
255
247
|
filters[dep_defaults.LIMIT_OFFSET_FILTER_DEPENDENCY_KEY] = Provide(
|
|
256
248
|
provide_limit_offset_pagination, sync_to_thread=False
|
|
@@ -260,10 +252,7 @@ def _create_statement_filters(
|
|
|
260
252
|
|
|
261
253
|
def provide_search_filter(
|
|
262
254
|
search_string: StringOrNone = Parameter(
|
|
263
|
-
title="Field to search",
|
|
264
|
-
query="searchString",
|
|
265
|
-
default=None,
|
|
266
|
-
required=False,
|
|
255
|
+
title="Field to search", query="searchString", default=None, required=False
|
|
267
256
|
),
|
|
268
257
|
ignore_case: BooleanOrNone = Parameter(
|
|
269
258
|
title="Search should be case sensitive",
|
|
@@ -287,19 +276,13 @@ def _create_statement_filters(
|
|
|
287
276
|
|
|
288
277
|
def provide_order_by(
|
|
289
278
|
field_name: StringOrNone = Parameter(
|
|
290
|
-
title="Order by field",
|
|
291
|
-
query="orderBy",
|
|
292
|
-
default=sort_field,
|
|
293
|
-
required=False,
|
|
279
|
+
title="Order by field", query="orderBy", default=sort_field, required=False
|
|
294
280
|
),
|
|
295
281
|
sort_order: SortOrderOrNone = Parameter(
|
|
296
|
-
title="Field to search",
|
|
297
|
-
query="sortOrder",
|
|
298
|
-
default=config.get("sort_order", "desc"),
|
|
299
|
-
required=False,
|
|
282
|
+
title="Field to search", query="sortOrder", default=config.get("sort_order", "desc"), required=False
|
|
300
283
|
),
|
|
301
|
-
) ->
|
|
302
|
-
return
|
|
284
|
+
) -> OrderByFilter:
|
|
285
|
+
return OrderByFilter(field_name=field_name, sort_order=sort_order) # type: ignore[arg-type]
|
|
303
286
|
|
|
304
287
|
filters[dep_defaults.ORDER_BY_FILTER_DEPENDENCY_KEY] = Provide(provide_order_by, sync_to_thread=False)
|
|
305
288
|
|
|
@@ -340,14 +323,14 @@ def _create_statement_filters(
|
|
|
340
323
|
|
|
341
324
|
def create_in_filter_provider( # pyright: ignore
|
|
342
325
|
field_name: FieldNameType,
|
|
343
|
-
) -> Callable[..., Optional[
|
|
326
|
+
) -> Callable[..., Optional[InCollectionFilter[field_def.type_hint]]]: # type: ignore # pyright: ignore
|
|
344
327
|
def provide_in_filter( # pyright: ignore
|
|
345
328
|
values: Optional[list[field_name.type_hint]] = Parameter( # type: ignore # pyright: ignore
|
|
346
329
|
query=camelize(f"{field_name.name}_in"), default=None, required=False
|
|
347
330
|
),
|
|
348
|
-
) -> Optional[
|
|
331
|
+
) -> Optional[InCollectionFilter[field_name.type_hint]]: # type: ignore # pyright: ignore
|
|
349
332
|
return (
|
|
350
|
-
|
|
333
|
+
InCollectionFilter[field_name.type_hint](field_name=field_name.name, values=values) # type: ignore # pyright: ignore
|
|
351
334
|
if values
|
|
352
335
|
else None
|
|
353
336
|
)
|
|
@@ -365,7 +348,7 @@ def _create_statement_filters(
|
|
|
365
348
|
return filters
|
|
366
349
|
|
|
367
350
|
|
|
368
|
-
def _create_filter_aggregate_function(config: FilterConfig) -> Callable[..., list[FilterTypes]]:
|
|
351
|
+
def _create_filter_aggregate_function(config: FilterConfig) -> Callable[..., list[FilterTypes]]:
|
|
369
352
|
"""Create a filter function based on the provided configuration.
|
|
370
353
|
|
|
371
354
|
Args:
|
|
@@ -384,27 +367,27 @@ def _create_filter_aggregate_function(config: FilterConfig) -> Callable[..., lis
|
|
|
384
367
|
name="id_filter",
|
|
385
368
|
kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
386
369
|
default=Dependency(skip_validation=True),
|
|
387
|
-
annotation=
|
|
370
|
+
annotation=InCollectionFilter[cls], # type: ignore[valid-type]
|
|
388
371
|
)
|
|
389
|
-
annotations["id_filter"] =
|
|
372
|
+
annotations["id_filter"] = InCollectionFilter[cls] # type: ignore[valid-type]
|
|
390
373
|
|
|
391
374
|
if config.get("created_at"):
|
|
392
375
|
parameters["created_filter"] = inspect.Parameter(
|
|
393
376
|
name="created_filter",
|
|
394
377
|
kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
395
378
|
default=Dependency(skip_validation=True),
|
|
396
|
-
annotation=
|
|
379
|
+
annotation=BeforeAfterFilter,
|
|
397
380
|
)
|
|
398
|
-
annotations["created_filter"] =
|
|
381
|
+
annotations["created_filter"] = BeforeAfterFilter
|
|
399
382
|
|
|
400
383
|
if config.get("updated_at"):
|
|
401
384
|
parameters["updated_filter"] = inspect.Parameter(
|
|
402
385
|
name="updated_filter",
|
|
403
386
|
kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
404
387
|
default=Dependency(skip_validation=True),
|
|
405
|
-
annotation=
|
|
388
|
+
annotation=BeforeAfterFilter,
|
|
406
389
|
)
|
|
407
|
-
annotations["updated_filter"] =
|
|
390
|
+
annotations["updated_filter"] = BeforeAfterFilter
|
|
408
391
|
|
|
409
392
|
if config.get("search"):
|
|
410
393
|
parameters["search_filter"] = inspect.Parameter(
|
|
@@ -420,18 +403,18 @@ def _create_filter_aggregate_function(config: FilterConfig) -> Callable[..., lis
|
|
|
420
403
|
name="limit_offset_filter",
|
|
421
404
|
kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
422
405
|
default=Dependency(skip_validation=True),
|
|
423
|
-
annotation=
|
|
406
|
+
annotation=LimitOffsetFilter,
|
|
424
407
|
)
|
|
425
|
-
annotations["limit_offset_filter"] =
|
|
408
|
+
annotations["limit_offset_filter"] = LimitOffsetFilter
|
|
426
409
|
|
|
427
410
|
if config.get("sort_field"):
|
|
428
411
|
parameters["order_by_filter"] = inspect.Parameter(
|
|
429
412
|
name="order_by_filter",
|
|
430
413
|
kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
431
414
|
default=Dependency(skip_validation=True),
|
|
432
|
-
annotation=
|
|
415
|
+
annotation=OrderByFilter,
|
|
433
416
|
)
|
|
434
|
-
annotations["order_by_filter"] =
|
|
417
|
+
annotations["order_by_filter"] = OrderByFilter
|
|
435
418
|
|
|
436
419
|
# Add parameters for not_in filters
|
|
437
420
|
if not_in_fields := config.get("not_in_fields"):
|
|
@@ -453,9 +436,9 @@ def _create_filter_aggregate_function(config: FilterConfig) -> Callable[..., lis
|
|
|
453
436
|
name=f"{field_def.name}_in_filter",
|
|
454
437
|
kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
455
438
|
default=Dependency(skip_validation=True),
|
|
456
|
-
annotation=
|
|
439
|
+
annotation=InCollectionFilter[field_def.type_hint], # type: ignore
|
|
457
440
|
)
|
|
458
|
-
annotations[f"{field_def.name}_in_filter"] =
|
|
441
|
+
annotations[f"{field_def.name}_in_filter"] = InCollectionFilter[field_def.type_hint] # type: ignore
|
|
459
442
|
|
|
460
443
|
def provide_filters(**kwargs: FilterTypes) -> list[FilterTypes]:
|
|
461
444
|
"""Provide filter dependencies based on configuration.
|
|
@@ -483,7 +466,7 @@ def _create_filter_aggregate_function(config: FilterConfig) -> Callable[..., lis
|
|
|
483
466
|
):
|
|
484
467
|
filters.append(search_filter)
|
|
485
468
|
if (
|
|
486
|
-
(order_by := cast("Optional[
|
|
469
|
+
(order_by := cast("Optional[OrderByFilter]", kwargs.get("order_by_filter")))
|
|
487
470
|
and order_by is not None # pyright: ignore[reportUnnecessaryComparison]
|
|
488
471
|
and order_by.field_name is not None # pyright: ignore[reportUnnecessaryComparison]
|
|
489
472
|
):
|
|
@@ -512,8 +495,7 @@ def _create_filter_aggregate_function(config: FilterConfig) -> Callable[..., lis
|
|
|
512
495
|
|
|
513
496
|
# Set both signature and annotations
|
|
514
497
|
provide_filters.__signature__ = inspect.Signature( # type: ignore
|
|
515
|
-
parameters=list(parameters.values()),
|
|
516
|
-
return_annotation=list[FilterTypes],
|
|
498
|
+
parameters=list(parameters.values()), return_annotation=list[FilterTypes]
|
|
517
499
|
)
|
|
518
500
|
provide_filters.__annotations__ = annotations
|
|
519
501
|
provide_filters.__annotations__["return"] = list[FilterTypes]
|