fastapi-sqlalchemy-toolkit 0.7.10__tar.gz → 0.7.12__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.
Files changed (59) hide show
  1. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/PKG-INFO +2 -2
  2. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/ru/sorting.md +5 -5
  3. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/fastapi_sqlalchemy_toolkit/model_manager.py +43 -6
  4. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/pyproject.toml +1 -1
  5. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/.flake8 +0 -0
  6. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/.github/workflows/docker-test.yml +0 -0
  7. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/.github/workflows/python-publish.yml +0 -0
  8. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/.gitignore +0 -0
  9. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/.pylintrc +0 -0
  10. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/AUTHORS +0 -0
  11. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/LICENSE +0 -0
  12. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/Makefile +0 -0
  13. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/README.md +0 -0
  14. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/benefits.md +0 -0
  15. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/db_validation.md +0 -0
  16. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/extension.md +0 -0
  17. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/filtering.md +0 -0
  18. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/index.md +0 -0
  19. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/ru/benefits.md +0 -0
  20. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/ru/db_validation.md +0 -0
  21. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/ru/extension.md +0 -0
  22. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/ru/filtering.md +0 -0
  23. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/ru/index.md +0 -0
  24. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/ru/transactions.md +0 -0
  25. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/ru/usage.md +0 -0
  26. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/ru/utils.md +0 -0
  27. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/sorting.md +0 -0
  28. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/transactions.md +0 -0
  29. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/usage.md +0 -0
  30. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/docs/utils.md +0 -0
  31. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/examples/app/.env +0 -0
  32. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/examples/app/__init__.py +0 -0
  33. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/examples/app/api/__init__.py +0 -0
  34. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/examples/app/api/api.py +0 -0
  35. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/examples/app/api/deps.py +0 -0
  36. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/examples/app/api/endpoints/__init__.py +0 -0
  37. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/examples/app/api/endpoints/child.py +0 -0
  38. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/examples/app/config.py +0 -0
  39. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/examples/app/db.py +0 -0
  40. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/examples/app/main.py +0 -0
  41. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/examples/app/managers.py +0 -0
  42. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/examples/app/models.py +0 -0
  43. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/examples/app/schemas.py +0 -0
  44. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/fastapi_sqlalchemy_toolkit/__init__.py +0 -0
  45. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/fastapi_sqlalchemy_toolkit/filters.py +0 -0
  46. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/fastapi_sqlalchemy_toolkit/ordering.py +0 -0
  47. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/fastapi_sqlalchemy_toolkit/utils.py +0 -0
  48. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/mkdocs.yml +0 -0
  49. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/requirements/base.txt +0 -0
  50. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/requirements/docs.txt +0 -0
  51. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/requirements/lint.txt +0 -0
  52. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/requirements/test.txt +0 -0
  53. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/tests/Dockerfile +0 -0
  54. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/tests/__init__.py +0 -0
  55. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/tests/conftest.py +0 -0
  56. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/tests/db.py +0 -0
  57. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/tests/docker-compose.yml +0 -0
  58. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/tests/models.py +0 -0
  59. {fastapi_sqlalchemy_toolkit-0.7.10 → fastapi_sqlalchemy_toolkit-0.7.12}/tests/test_public_methods.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: fastapi_sqlalchemy_toolkit
3
- Version: 0.7.10
3
+ Version: 0.7.12
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
- 1. Cпискок или кортеж полей основной модели:
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
- 2. Маппинг строковых полей для сортировки на соответствующие поля моделей:
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
- - Передать параметр сортировки как параметр `order_by` в методы `ModelManager`
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
@@ -486,6 +486,8 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
486
486
  options: List[Any] | Any | None = None,
487
487
  where: Any | None = None,
488
488
  base_stmt: Select | None = None,
489
+ limit: int | None = None,
490
+ offset: int | None = None,
489
491
  *,
490
492
  unique: bool = False,
491
493
  **simple_filters: Any,
@@ -507,12 +509,24 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
507
509
  :param base_stmt: объект Select для SQL запроса. Если передан, то метод вернёт
508
510
  список Row, а не ModelT.
509
511
 
512
+ :param limit: ограничение, передаётся в параметр limit запроса SQLAlchemy
513
+
514
+ :param offset: смещение, передаётся в параметр offset запроса SQLAlchemy
515
+
510
516
  :param simple_filters: параметры для фильтрации по точному соответствию,
511
517
  аналогично методу .filter_by() SQLAlchemy
512
518
 
513
519
  :returns: список объектов или Row
514
520
  """
515
- stmt = self.assemble_stmt(base_stmt, order_by, options, where, **simple_filters)
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
+ )
516
530
  result = await session.execute(stmt)
517
531
 
518
532
  if base_stmt is None:
@@ -532,6 +546,8 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
532
546
  options: List[Any] | Any | None = None,
533
547
  where: Any | None = None,
534
548
  base_stmt: Select | None = None,
549
+ limit: int | None = None,
550
+ offset: int | None = None,
535
551
  *,
536
552
  unique: bool = False,
537
553
  **simple_filters: Any,
@@ -565,6 +581,10 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
565
581
  Примечание: фильтрация и сортировка по связанным моделям скорее всего
566
582
  не будут работать вместе с этим параметром.
567
583
 
584
+ :param limit: ограничение, передаётся в параметр limit запроса SQLAlchemy
585
+
586
+ :param offset: смещение, передаётся в параметр offset запроса SQLAlchemy
587
+
568
588
  :param simple_filters: параметры для фильтрации по точному соответствию,
569
589
  аналогично методу .filter_by() SQLAlchemy
570
590
 
@@ -579,7 +599,15 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
579
599
  self.handle_nullable_filter_expressions(nullable_filter_expressions)
580
600
  filter_expressions = filter_expressions | nullable_filter_expressions
581
601
 
582
- stmt = self.assemble_stmt(base_stmt, order_by, options, where, **simple_filters)
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
+ )
583
611
  stmt = self.get_joins(
584
612
  stmt,
585
613
  options=options,
@@ -669,7 +697,9 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
669
697
  """
670
698
  update_data = in_obj.model_dump(exclude_unset=exclude_unset) if in_obj else {}
671
699
  update_data.update(attrs)
672
- update_data = await self.run_db_validation(session, db_obj=db_obj, in_obj=update_data)
700
+ update_data = await self.run_db_validation(
701
+ session, db_obj=db_obj, in_obj=update_data
702
+ )
673
703
  for field in update_data:
674
704
  setattr(db_obj, field, update_data[field])
675
705
  await self.save(session, commit=commit)
@@ -716,7 +746,7 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
716
746
  stmt = update(self.model).values(update_data)
717
747
  if ids:
718
748
  stmt = stmt.where(self.model.id.in_(ids))
719
- elif where:
749
+ elif where is not None:
720
750
  stmt = stmt.where(where)
721
751
  if returning:
722
752
  stmt = stmt.returning(self.model)
@@ -772,7 +802,7 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
772
802
  stmt = delete(self.model)
773
803
  if ids:
774
804
  stmt = stmt.where(self.model.id.in_(ids))
775
- elif where:
805
+ elif where is not None:
776
806
  stmt = stmt.where(where)
777
807
  await session.execute(stmt)
778
808
  await self.save(session, commit=commit)
@@ -951,6 +981,8 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
951
981
  order_by: InstrumentedAttribute | UnaryExpression | None = None,
952
982
  options: List[Any] | Any | None = None,
953
983
  where: Any | None = None,
984
+ limit: int | None = None,
985
+ offset: int | None = None,
954
986
  **simple_filters: Any,
955
987
  ) -> Select:
956
988
  if base_stmt is not None:
@@ -992,6 +1024,11 @@ class ModelManager(Generic[ModelT, CreateSchemaT, UpdateSchemaT]):
992
1024
  else:
993
1025
  stmt = stmt.where(where)
994
1026
 
1027
+ if limit is not None:
1028
+ stmt = stmt.limit(limit)
1029
+ if offset is not None:
1030
+ stmt = stmt.offset(offset)
1031
+
995
1032
  return stmt
996
1033
 
997
1034
  async def validate_fk_exists(
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "fastapi_sqlalchemy_toolkit"
7
- version = "0.7.10"
7
+ version = "0.7.12"
8
8
  authors = [
9
9
  { name="Egor Kondrashov", email="e.kondr01@gmail.com" },
10
10
  ]