fastapi-sqlalchemy-toolkit 0.7.9__tar.gz → 0.7.11__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.9 → fastapi_sqlalchemy_toolkit-0.7.11}/PKG-INFO +2 -2
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/ru/sorting.md +5 -5
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/fastapi_sqlalchemy_toolkit/model_manager.py +44 -5
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/pyproject.toml +1 -1
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/.flake8 +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/.github/workflows/docker-test.yml +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/.github/workflows/python-publish.yml +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/.gitignore +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/.pylintrc +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/AUTHORS +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/LICENSE +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/Makefile +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/README.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/benefits.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/db_validation.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/extension.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/filtering.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/index.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/ru/benefits.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/ru/db_validation.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/ru/extension.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/ru/filtering.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/ru/index.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/ru/transactions.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/ru/usage.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/ru/utils.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/sorting.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/transactions.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/usage.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/utils.md +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/.env +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/__init__.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/api/__init__.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/api/api.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/api/deps.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/api/endpoints/__init__.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/api/endpoints/child.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/config.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/db.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/main.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/managers.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/models.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/schemas.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/fastapi_sqlalchemy_toolkit/__init__.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/fastapi_sqlalchemy_toolkit/filters.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/fastapi_sqlalchemy_toolkit/ordering.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/fastapi_sqlalchemy_toolkit/utils.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/mkdocs.yml +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/requirements/base.txt +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/requirements/docs.txt +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/requirements/lint.txt +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/requirements/test.txt +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/tests/Dockerfile +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/tests/__init__.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/tests/conftest.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/tests/db.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/tests/docker-compose.yml +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/tests/models.py +0 -0
- {fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/tests/test_public_methods.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: fastapi_sqlalchemy_toolkit
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.11
|
|
4
4
|
Summary: FastAPI SQLAlchemy Toolkit
|
|
5
5
|
Project-URL: Homepage, https://github.com/e-kondr01/fastapi-sqlalchemy-toolkit
|
|
6
6
|
Author-email: Egor Kondrashov <e.kondr01@gmail.com>
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
Для применения декларативной сортировки нужно:
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
## Определить поля, по которым доступна фильтрация
|
|
11
11
|
|
|
12
12
|
Это может быть:
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
- Cписок или кортеж полей основной модели:
|
|
15
15
|
|
|
16
16
|
```python
|
|
17
17
|
from app.models import Child
|
|
@@ -27,7 +27,7 @@ child_ordering_fields = (
|
|
|
27
27
|
|
|
28
28
|
Дефис первым символом означает направление сортировки по убыванию.
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
- Маппинг строковых полей для сортировки на соответствующие поля моделей:
|
|
31
31
|
|
|
32
32
|
```python
|
|
33
33
|
from app.models import Child, Parent
|
|
@@ -41,7 +41,7 @@ child_ordering_fields = {
|
|
|
41
41
|
В таком случае, будут доступны следующий параметря для сортировки:
|
|
42
42
|
`title`, `-title`, `parent_title`, `-parent_title`.
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
## В параметрах энпдоинта передать определённый выше список
|
|
45
45
|
в `ordering_depends`
|
|
46
46
|
|
|
47
47
|
```python
|
|
@@ -55,7 +55,7 @@ async def get_child_objects(
|
|
|
55
55
|
...
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
## Передать параметр сортировки как параметр `order_by` в методы `ModelManager`
|
|
59
59
|
|
|
60
60
|
```python
|
|
61
61
|
return await child_manager.list(session=session, order_by=order_by)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ruff: noqa: UP006
|
|
2
2
|
from collections.abc import Callable, Iterable
|
|
3
|
-
from typing import Any, Generic, List, TypeVar # noqa: UP035
|
|
3
|
+
from typing import Any, Generic, List, TypeVar, overload # noqa: UP035
|
|
4
4
|
|
|
5
5
|
from fastapi import HTTPException, status
|
|
6
6
|
from fastapi_pagination.bases import BasePage
|
|
@@ -243,7 +243,9 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
|
|
|
243
243
|
|
|
244
244
|
result = await session.execute(stmt)
|
|
245
245
|
if base_stmt is None:
|
|
246
|
-
|
|
246
|
+
if order_by is not None:
|
|
247
|
+
return result.scalars().first()
|
|
248
|
+
return result.scalar_one_or_none()
|
|
247
249
|
return result.first()
|
|
248
250
|
|
|
249
251
|
async def get_or_404(
|
|
@@ -484,6 +486,8 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
|
|
|
484
486
|
options: List[Any] | Any | None = None,
|
|
485
487
|
where: Any | None = None,
|
|
486
488
|
base_stmt: Select | None = None,
|
|
489
|
+
limit: int | None = None,
|
|
490
|
+
offset: int | None = None,
|
|
487
491
|
*,
|
|
488
492
|
unique: bool = False,
|
|
489
493
|
**simple_filters: Any,
|
|
@@ -505,12 +509,24 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
|
|
|
505
509
|
:param base_stmt: объект Select для SQL запроса. Если передан, то метод вернёт
|
|
506
510
|
список Row, а не ModelT.
|
|
507
511
|
|
|
512
|
+
:param limit: ограничение, передаётся в параметр limit запроса SQLAlchemy
|
|
513
|
+
|
|
514
|
+
:param offset: смещение, передаётся в параметр offset запроса SQLAlchemy
|
|
515
|
+
|
|
508
516
|
:param simple_filters: параметры для фильтрации по точному соответствию,
|
|
509
517
|
аналогично методу .filter_by() SQLAlchemy
|
|
510
518
|
|
|
511
519
|
:returns: список объектов или Row
|
|
512
520
|
"""
|
|
513
|
-
stmt = self.assemble_stmt(
|
|
521
|
+
stmt = self.assemble_stmt(
|
|
522
|
+
base_stmt,
|
|
523
|
+
order_by,
|
|
524
|
+
options,
|
|
525
|
+
where,
|
|
526
|
+
limit=limit,
|
|
527
|
+
offset=offset,
|
|
528
|
+
**simple_filters,
|
|
529
|
+
)
|
|
514
530
|
result = await session.execute(stmt)
|
|
515
531
|
|
|
516
532
|
if base_stmt is None:
|
|
@@ -530,6 +546,8 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
|
|
|
530
546
|
options: List[Any] | Any | None = None,
|
|
531
547
|
where: Any | None = None,
|
|
532
548
|
base_stmt: Select | None = None,
|
|
549
|
+
limit: int | None = None,
|
|
550
|
+
offset: int | None = None,
|
|
533
551
|
*,
|
|
534
552
|
unique: bool = False,
|
|
535
553
|
**simple_filters: Any,
|
|
@@ -563,6 +581,10 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
|
|
|
563
581
|
Примечание: фильтрация и сортировка по связанным моделям скорее всего
|
|
564
582
|
не будут работать вместе с этим параметром.
|
|
565
583
|
|
|
584
|
+
:param limit: ограничение, передаётся в параметр limit запроса SQLAlchemy
|
|
585
|
+
|
|
586
|
+
:param offset: смещение, передаётся в параметр offset запроса SQLAlchemy
|
|
587
|
+
|
|
566
588
|
:param simple_filters: параметры для фильтрации по точному соответствию,
|
|
567
589
|
аналогично методу .filter_by() SQLAlchemy
|
|
568
590
|
|
|
@@ -577,7 +599,15 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
|
|
|
577
599
|
self.handle_nullable_filter_expressions(nullable_filter_expressions)
|
|
578
600
|
filter_expressions = filter_expressions | nullable_filter_expressions
|
|
579
601
|
|
|
580
|
-
stmt = self.assemble_stmt(
|
|
602
|
+
stmt = self.assemble_stmt(
|
|
603
|
+
base_stmt,
|
|
604
|
+
order_by,
|
|
605
|
+
options,
|
|
606
|
+
where,
|
|
607
|
+
limit=limit,
|
|
608
|
+
offset=offset,
|
|
609
|
+
**simple_filters,
|
|
610
|
+
)
|
|
581
611
|
stmt = self.get_joins(
|
|
582
612
|
stmt,
|
|
583
613
|
options=options,
|
|
@@ -667,7 +697,9 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
|
|
|
667
697
|
"""
|
|
668
698
|
update_data = in_obj.model_dump(exclude_unset=exclude_unset) if in_obj else {}
|
|
669
699
|
update_data.update(attrs)
|
|
670
|
-
update_data = await self.run_db_validation(
|
|
700
|
+
update_data = await self.run_db_validation(
|
|
701
|
+
session, db_obj=db_obj, in_obj=update_data
|
|
702
|
+
)
|
|
671
703
|
for field in update_data:
|
|
672
704
|
setattr(db_obj, field, update_data[field])
|
|
673
705
|
await self.save(session, commit=commit)
|
|
@@ -949,6 +981,8 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
|
|
|
949
981
|
order_by: InstrumentedAttribute | UnaryExpression | None = None,
|
|
950
982
|
options: List[Any] | Any | None = None,
|
|
951
983
|
where: Any | None = None,
|
|
984
|
+
limit: int | None = None,
|
|
985
|
+
offset: int | None = None,
|
|
952
986
|
**simple_filters: Any,
|
|
953
987
|
) -> Select:
|
|
954
988
|
if base_stmt is not None:
|
|
@@ -990,6 +1024,11 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
|
|
|
990
1024
|
else:
|
|
991
1025
|
stmt = stmt.where(where)
|
|
992
1026
|
|
|
1027
|
+
if limit is not None:
|
|
1028
|
+
stmt = stmt.limit(limit)
|
|
1029
|
+
if offset is not None:
|
|
1030
|
+
stmt = stmt.offset(offset)
|
|
1031
|
+
|
|
993
1032
|
return stmt
|
|
994
1033
|
|
|
995
1034
|
async def validate_fk_exists(
|
|
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.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/db_validation.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/docs/ru/db_validation.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/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.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/__init__.py
RENAMED
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/api/__init__.py
RENAMED
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/api/api.py
RENAMED
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/api/deps.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/config.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/managers.py
RENAMED
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/models.py
RENAMED
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/examples/app/schemas.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/requirements/base.txt
RENAMED
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/requirements/docs.txt
RENAMED
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/requirements/lint.txt
RENAMED
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/requirements/test.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/tests/docker-compose.yml
RENAMED
|
File without changes
|
|
File without changes
|
{fastapi_sqlalchemy_toolkit-0.7.9 → fastapi_sqlalchemy_toolkit-0.7.11}/tests/test_public_methods.py
RENAMED
|
File without changes
|