fastapi-sqlalchemy-toolkit 0.7.6__tar.gz → 0.7.7__tar.gz
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.
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/.gitignore +2 -1
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/PKG-INFO +1 -1
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/ru/sorting.md +6 -5
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/fastapi_sqlalchemy_toolkit/model_manager.py +9 -8
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/pyproject.toml +1 -1
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/.flake8 +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/.github/workflows/docker-test.yml +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/.github/workflows/python-publish.yml +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/.pylintrc +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/AUTHORS +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/LICENSE +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/Makefile +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/README.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/benefits.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/db_validation.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/extension.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/filtering.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/index.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/ru/benefits.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/ru/db_validation.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/ru/extension.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/ru/filtering.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/ru/index.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/ru/transactions.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/ru/usage.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/ru/utils.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/sorting.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/transactions.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/usage.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/utils.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/.env +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/__init__.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/api/__init__.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/api/api.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/api/deps.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/api/endpoints/__init__.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/api/endpoints/child.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/config.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/db.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/main.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/managers.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/models.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/schemas.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/fastapi_sqlalchemy_toolkit/__init__.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/fastapi_sqlalchemy_toolkit/filters.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/fastapi_sqlalchemy_toolkit/ordering.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/fastapi_sqlalchemy_toolkit/utils.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/mkdocs.yml +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/requirements/base.txt +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/requirements/docs.txt +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/requirements/lint.txt +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/requirements/test.txt +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/tests/Dockerfile +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/tests/__init__.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/tests/conftest.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/tests/db.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/tests/docker-compose.yml +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/tests/models.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/tests/test_public_methods.py +0 -0
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
- Определить поля, по которым доступна фильтрация.
|
|
11
11
|
|
|
12
|
-
Это может
|
|
12
|
+
Это может быть:
|
|
13
|
+
|
|
14
|
+
1. Cпискок или кортеж полей основной модели:
|
|
13
15
|
|
|
14
16
|
```python
|
|
15
17
|
from app.models import Child
|
|
@@ -25,16 +27,15 @@ child_ordering_fields = (
|
|
|
25
27
|
|
|
26
28
|
Дефис первым символом означает направление сортировки по убыванию.
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
на соответствующие поля моделей:
|
|
30
|
+
2. Маппинг строковых полей для сортировки на соответствующие поля моделей:
|
|
30
31
|
|
|
31
32
|
```python
|
|
32
33
|
from app.models import Child, Parent
|
|
33
34
|
|
|
34
|
-
child_ordering_fields =
|
|
35
|
+
child_ordering_fields = {
|
|
35
36
|
"title": MyModel.title,
|
|
36
37
|
"parent_title": ParentModel.title
|
|
37
|
-
|
|
38
|
+
}
|
|
38
39
|
```
|
|
39
40
|
|
|
40
41
|
В таком случае, будут доступны следующий параметря для сортировки:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ruff: noqa: UP006
|
|
2
2
|
from collections.abc import Callable, Iterable
|
|
3
|
-
from typing import Any,
|
|
3
|
+
from typing import Any, List # noqa: UP035
|
|
4
4
|
|
|
5
5
|
from fastapi import HTTPException, status
|
|
6
6
|
from fastapi_pagination.bases import BasePage
|
|
@@ -30,19 +30,20 @@ from sqlalchemy.sql.selectable import Exists
|
|
|
30
30
|
|
|
31
31
|
from .filters import null_query_values
|
|
32
32
|
|
|
33
|
-
ModelT = TypeVar("ModelT", bound=DeclarativeBase)
|
|
34
|
-
CreateSchemaT = TypeVar("CreateSchemaT", bound=BaseModel)
|
|
35
|
-
UpdateSchemaT = TypeVar("UpdateSchemaT", bound=BaseModel)
|
|
36
33
|
ModelDict = dict[str, Any]
|
|
37
34
|
|
|
38
35
|
|
|
39
|
-
def sqlalchemy_model_to_dict(model:
|
|
36
|
+
def sqlalchemy_model_to_dict(model: DeclarativeBase) -> dict:
|
|
40
37
|
db_obj_dict = model.__dict__.copy()
|
|
41
38
|
del db_obj_dict["_sa_instance_state"]
|
|
42
39
|
return db_obj_dict
|
|
43
40
|
|
|
44
41
|
|
|
45
|
-
class ModelManager
|
|
42
|
+
class ModelManager[
|
|
43
|
+
ModelT: DeclarativeBase,
|
|
44
|
+
CreateSchemaT: BaseModel,
|
|
45
|
+
UpdateSchemaT: BaseModel,
|
|
46
|
+
]:
|
|
46
47
|
def __init__(
|
|
47
48
|
self,
|
|
48
49
|
model: type[ModelT],
|
|
@@ -85,7 +86,8 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
|
|
|
85
86
|
self.defaults: dict[str, Any] = {}
|
|
86
87
|
|
|
87
88
|
attr: InstrumentedAttribute
|
|
88
|
-
|
|
89
|
+
model_attrs = self.model.__dict__.copy()
|
|
90
|
+
for attr_name, attr in model_attrs.items():
|
|
89
91
|
# Перебираем только атрибуты модели
|
|
90
92
|
if not attr_name.startswith("_"):
|
|
91
93
|
# Обрабатываем связи
|
|
@@ -669,7 +671,6 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
|
|
|
669
671
|
await self.run_db_validation(session, db_obj=db_obj, in_obj=update_data)
|
|
670
672
|
for field in update_data:
|
|
671
673
|
setattr(db_obj, field, update_data[field])
|
|
672
|
-
session.add(db_obj)
|
|
673
674
|
await self.save(session, commit=commit)
|
|
674
675
|
await session.refresh(db_obj, attribute_names=refresh_attribute_names)
|
|
675
676
|
return db_obj
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/ru/db_validation.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/docs/ru/transactions.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/__init__.py
RENAMED
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/api/__init__.py
RENAMED
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/api/api.py
RENAMED
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/api/deps.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/config.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/managers.py
RENAMED
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/models.py
RENAMED
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/examples/app/schemas.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/tests/docker-compose.yml
RENAMED
|
File without changes
|
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.6 → fastapi_sqlalchemy_toolkit-0.7.7}/tests/test_public_methods.py
RENAMED
|
File without changes
|