fastapi-sqla 3.1.1__tar.gz → 3.1.2__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.
Potentially problematic release.
This version of fastapi-sqla might be problematic. Click here for more details.
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/PKG-INFO +3 -3
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/fastapi_sqla/async_pagination.py +12 -12
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/fastapi_sqla/pagination.py +19 -19
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/fastapi_sqla/sqla.py +4 -7
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/pyproject.toml +3 -3
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/LICENSE +0 -0
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/README.md +0 -0
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/fastapi_sqla/__init__.py +0 -0
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/fastapi_sqla/_pytest_plugin.py +0 -0
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/fastapi_sqla/async_sqla.py +0 -0
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/fastapi_sqla/aws_aurora_support.py +0 -0
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/fastapi_sqla/aws_rds_iam_support.py +0 -0
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/fastapi_sqla/base.py +0 -0
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/fastapi_sqla/models.py +0 -0
- {fastapi_sqla-3.1.1 → fastapi_sqla-3.1.2}/fastapi_sqla/py.typed +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: fastapi-sqla
|
|
3
|
-
Version: 3.1.
|
|
4
|
-
Summary: SQLAlchemy extension for FastAPI with support for pagination, asyncio, and pytest, ready for production.
|
|
3
|
+
Version: 3.1.2
|
|
4
|
+
Summary: SQLAlchemy extension for FastAPI with support for pagination, asyncio, SQLModel, and pytest, ready for production.
|
|
5
5
|
Home-page: https://github.com/dialoguemd/fastapi-sqla
|
|
6
6
|
License: MIT
|
|
7
7
|
Keywords: FastAPI,SQLAlchemy,asyncio,pytest,alembic
|
|
@@ -46,7 +46,7 @@ Requires-Dist: fastapi (>=0.95.1)
|
|
|
46
46
|
Requires-Dist: greenlet (>=1.1.3,<2.0.0) ; extra == "tests"
|
|
47
47
|
Requires-Dist: httpx (>=0.23.0,<0.24.0) ; extra == "tests"
|
|
48
48
|
Requires-Dist: isort (>=5.5.3,<6.0.0) ; extra == "tests"
|
|
49
|
-
Requires-Dist: mypy[tests] (>=0.
|
|
49
|
+
Requires-Dist: mypy[tests] (>=1.0.0,<2.0.0) ; extra == "tests"
|
|
50
50
|
Requires-Dist: pdbpp (>=0.10.2,<0.11.0) ; extra == "tests"
|
|
51
51
|
Requires-Dist: psycopg2 (>=2.8.6,<3.0.0) ; extra == "tests"
|
|
52
52
|
Requires-Dist: pydantic (>=1)
|
|
@@ -6,7 +6,7 @@ from fastapi import Depends, Query
|
|
|
6
6
|
from sqlalchemy.sql import Select, func, select
|
|
7
7
|
|
|
8
8
|
from fastapi_sqla.async_sqla import AsyncSessionDependency, SqlaAsyncSession
|
|
9
|
-
from fastapi_sqla.models import Page
|
|
9
|
+
from fastapi_sqla.models import Meta, Page
|
|
10
10
|
from fastapi_sqla.sqla import _DEFAULT_SESSION_KEY
|
|
11
11
|
|
|
12
12
|
QueryCountDependency = Callable[..., Awaitable[int]]
|
|
@@ -19,7 +19,7 @@ PaginateDependency = Union[DefaultDependency, WithQueryCountDependency]
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
async def default_query_count(session: SqlaAsyncSession, query: Select) -> int:
|
|
22
|
-
result = await session.execute(select(func.count()).select_from(query.subquery()))
|
|
22
|
+
result = await session.execute(select(func.count()).select_from(query.subquery()))
|
|
23
23
|
return cast(int, result.scalar())
|
|
24
24
|
|
|
25
25
|
|
|
@@ -33,20 +33,20 @@ async def paginate_query(
|
|
|
33
33
|
scalars: bool = True,
|
|
34
34
|
) -> Page:
|
|
35
35
|
total_pages = math.ceil(total_items / limit)
|
|
36
|
-
page_number = offset / limit + 1
|
|
37
|
-
query = query.offset(offset).limit(limit)
|
|
36
|
+
page_number = math.floor(offset / limit + 1)
|
|
37
|
+
query = query.offset(offset).limit(limit)
|
|
38
38
|
result = await session.execute(query)
|
|
39
39
|
data = iter(
|
|
40
|
-
cast(Iterator, result.unique().scalars() if scalars else result.mappings())
|
|
40
|
+
cast(Iterator, result.unique().scalars() if scalars else result.mappings())
|
|
41
41
|
)
|
|
42
42
|
return Page(
|
|
43
|
-
data=data,
|
|
44
|
-
meta=
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
data=data, # type: ignore # Expected to be a list
|
|
44
|
+
meta=Meta(
|
|
45
|
+
offset=offset,
|
|
46
|
+
total_items=total_items,
|
|
47
|
+
total_pages=total_pages,
|
|
48
|
+
page_number=page_number,
|
|
49
|
+
),
|
|
50
50
|
)
|
|
51
51
|
|
|
52
52
|
|
|
@@ -7,7 +7,7 @@ from fastapi import Depends, Query
|
|
|
7
7
|
from sqlalchemy.orm import Query as LegacyQuery
|
|
8
8
|
from sqlalchemy.sql import Select, func, select
|
|
9
9
|
|
|
10
|
-
from fastapi_sqla.models import Page
|
|
10
|
+
from fastapi_sqla.models import Meta, Page
|
|
11
11
|
from fastapi_sqla.sqla import _DEFAULT_SESSION_KEY, SessionDependency, SqlaSession
|
|
12
12
|
|
|
13
13
|
DbQuery = Union[LegacyQuery, Select]
|
|
@@ -66,15 +66,15 @@ def _paginate_legacy(
|
|
|
66
66
|
scalars: bool = True,
|
|
67
67
|
) -> Page:
|
|
68
68
|
total_pages = math.ceil(total_items / limit)
|
|
69
|
-
page_number = offset / limit + 1
|
|
69
|
+
page_number = math.floor(offset / limit + 1)
|
|
70
70
|
return Page(
|
|
71
|
-
data=query.offset(offset).limit(limit).all(),
|
|
72
|
-
meta=
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
data=query.offset(offset).limit(limit).all(),
|
|
72
|
+
meta=Meta(
|
|
73
|
+
offset=offset,
|
|
74
|
+
total_items=total_items,
|
|
75
|
+
total_pages=total_pages,
|
|
76
|
+
page_number=page_number,
|
|
77
|
+
),
|
|
78
78
|
)
|
|
79
79
|
|
|
80
80
|
|
|
@@ -89,20 +89,20 @@ def _paginate(
|
|
|
89
89
|
scalars: bool = True,
|
|
90
90
|
) -> Page:
|
|
91
91
|
total_pages = math.ceil(total_items / limit)
|
|
92
|
-
page_number = offset / limit + 1
|
|
93
|
-
query = query.offset(offset).limit(limit)
|
|
92
|
+
page_number = math.floor(offset / limit + 1)
|
|
93
|
+
query = query.offset(offset).limit(limit)
|
|
94
94
|
result = session.execute(query)
|
|
95
95
|
data = iter(
|
|
96
|
-
cast(Iterator, result.unique().scalars() if scalars else result.mappings())
|
|
96
|
+
cast(Iterator, result.unique().scalars() if scalars else result.mappings())
|
|
97
97
|
)
|
|
98
98
|
return Page(
|
|
99
|
-
data=data,
|
|
100
|
-
meta=
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
data=data, # type: ignore # Expected to be a list
|
|
100
|
+
meta=Meta(
|
|
101
|
+
offset=offset,
|
|
102
|
+
total_items=total_items,
|
|
103
|
+
total_pages=total_pages,
|
|
104
|
+
page_number=page_number,
|
|
105
|
+
),
|
|
106
106
|
)
|
|
107
107
|
|
|
108
108
|
|
|
@@ -2,7 +2,7 @@ import asyncio
|
|
|
2
2
|
import os
|
|
3
3
|
from collections.abc import Generator
|
|
4
4
|
from contextlib import contextmanager
|
|
5
|
-
from typing import Annotated
|
|
5
|
+
from typing import Annotated
|
|
6
6
|
|
|
7
7
|
import structlog
|
|
8
8
|
from fastapi import Depends, Request
|
|
@@ -165,14 +165,11 @@ async def add_session_to_request(
|
|
|
165
165
|
return response
|
|
166
166
|
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
class SessionDependency(Generic[S]):
|
|
168
|
+
class SessionDependency:
|
|
172
169
|
def __init__(self, key: str = _DEFAULT_SESSION_KEY) -> None:
|
|
173
170
|
self.key = key
|
|
174
171
|
|
|
175
|
-
def __call__(self, request: Request) ->
|
|
172
|
+
def __call__(self, request: Request) -> SqlaSession:
|
|
176
173
|
"""Yield the sqlalchemy session for that request.
|
|
177
174
|
|
|
178
175
|
It is meant to be used as a FastAPI dependency::
|
|
@@ -197,5 +194,5 @@ class SessionDependency(Generic[S]):
|
|
|
197
194
|
raise
|
|
198
195
|
|
|
199
196
|
|
|
200
|
-
default_session_dep = SessionDependency
|
|
197
|
+
default_session_dep = SessionDependency()
|
|
201
198
|
Session = Annotated[SqlaSession, Depends(default_session_dep)]
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
[tool]
|
|
2
2
|
[tool.poetry]
|
|
3
3
|
name = "fastapi-sqla"
|
|
4
|
-
version = "3.1.
|
|
5
|
-
description = "SQLAlchemy extension for FastAPI with support for pagination, asyncio, and pytest, ready for production."
|
|
4
|
+
version = "3.1.2"
|
|
5
|
+
description = "SQLAlchemy extension for FastAPI with support for pagination, asyncio, SQLModel, and pytest, ready for production."
|
|
6
6
|
authors = ["Hadrien David <hadrien.david@dialogue.co>", "Victor Repkow <victor.repkow@dialogue.co>"]
|
|
7
7
|
license = "MIT"
|
|
8
8
|
readme = "README.md"
|
|
@@ -64,7 +64,7 @@ optional = true
|
|
|
64
64
|
version = "^1.1.3"
|
|
65
65
|
optional = true
|
|
66
66
|
[tool.poetry.dependencies.mypy]
|
|
67
|
-
version = "^0.
|
|
67
|
+
version = "^1.0.0"
|
|
68
68
|
extras = ["tests"]
|
|
69
69
|
optional = true
|
|
70
70
|
[tool.poetry.dependencies.sqlmodel]
|
|
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
|