fastapi-extra 0.1.6__tar.gz → 0.1.8__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_extra-0.1.6 → fastapi_extra-0.1.8}/PKG-INFO +1 -1
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/__init__.py +1 -1
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/cache/redis.py +2 -2
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/database/driver.py +5 -3
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/database/model.py +1 -1
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/database/service.py +9 -7
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/database/session.py +2 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/dependency.py +3 -3
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/form.py +8 -1
- fastapi_extra-0.1.8/fastapi_extra/py.typed +0 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/types.py +2 -1
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra.egg-info/PKG-INFO +1 -1
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra.egg-info/SOURCES.txt +1 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/LICENSE +0 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/README.rst +0 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/cache/__init__.py +0 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/database/__init__.py +0 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/native/cursor.pyx +0 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/native/routing.pyx +0 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/response.py +0 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/settings.py +0 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra/utils.py +0 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra.egg-info/dependency_links.txt +0 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra.egg-info/requires.txt +0 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/fastapi_extra.egg-info/top_level.txt +0 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/pyproject.toml +0 -0
- {fastapi_extra-0.1.6 → fastapi_extra-0.1.8}/setup.cfg +0 -0
|
@@ -8,7 +8,7 @@ from fastapi.params import Depends
|
|
|
8
8
|
from pydantic import BaseModel, Field, RedisDsn
|
|
9
9
|
from redis.asyncio import ConnectionPool, Redis
|
|
10
10
|
|
|
11
|
-
from fastapi_extra.dependency import
|
|
11
|
+
from fastapi_extra.dependency import AbstractComponent
|
|
12
12
|
from fastapi_extra.settings import Settings
|
|
13
13
|
|
|
14
14
|
|
|
@@ -26,7 +26,7 @@ _settings = DefaultRedisSettings() # type: ignore
|
|
|
26
26
|
_loaded_pools: list[ConnectionPool] = []
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
class RedisCli(
|
|
29
|
+
class RedisCli(AbstractComponent):
|
|
30
30
|
default_config = _settings.redis
|
|
31
31
|
|
|
32
32
|
|
|
@@ -11,7 +11,7 @@ from sqlalchemy.util import _concurrency_py3k
|
|
|
11
11
|
from sqlmodel import Session, create_engine
|
|
12
12
|
from sqlmodel.ext.asyncio.session import AsyncSession
|
|
13
13
|
|
|
14
|
-
from fastapi_extra.dependency import
|
|
14
|
+
from fastapi_extra.dependency import AbstractComponent
|
|
15
15
|
from fastapi_extra.settings import Settings
|
|
16
16
|
|
|
17
17
|
|
|
@@ -37,7 +37,7 @@ _settings = DefaultDatabaseSettings() # type: ignore
|
|
|
37
37
|
_loaded_engines: list[Engine] = []
|
|
38
38
|
|
|
39
39
|
|
|
40
|
-
class DB(
|
|
40
|
+
class DB(AbstractComponent):
|
|
41
41
|
default_config = _settings.datasource
|
|
42
42
|
default_options = {}
|
|
43
43
|
|
|
@@ -65,7 +65,9 @@ class AsyncDB(DB):
|
|
|
65
65
|
|
|
66
66
|
@property
|
|
67
67
|
def engine(self) -> AsyncEngine:
|
|
68
|
-
|
|
68
|
+
if not self._engine:
|
|
69
|
+
self._engine = AsyncEngine(super().engine)
|
|
70
|
+
return self._engine
|
|
69
71
|
|
|
70
72
|
@property
|
|
71
73
|
def session(self) -> AsyncSession:
|
|
@@ -12,7 +12,7 @@ Model = TypeVar("Model", bound=SQLModel)
|
|
|
12
12
|
|
|
13
13
|
class ModelService(AbstractDependency, Generic[Model], annotated=False):
|
|
14
14
|
__slot__ = ("session", )
|
|
15
|
-
__model__:
|
|
15
|
+
__model__: Model
|
|
16
16
|
|
|
17
17
|
@classmethod
|
|
18
18
|
def __class_getitem__(cls, item: type[SQLModel]) -> Self:
|
|
@@ -20,8 +20,11 @@ class ModelService(AbstractDependency, Generic[Model], annotated=False):
|
|
|
20
20
|
raise TypeError(f"type[SQLModel] expected, got {item}")
|
|
21
21
|
if not (table_arg := item.model_config.get("table", None)):
|
|
22
22
|
raise AttributeError(f"True expected for argument {item.__name__}.model_config.table, got {table_arg}")
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
|
|
24
|
+
class SubService(ModelService):
|
|
25
|
+
__model__ = item
|
|
26
|
+
|
|
27
|
+
return SubService
|
|
25
28
|
|
|
26
29
|
def __init__(self, session: DefaultSession):
|
|
27
30
|
self.session = session
|
|
@@ -29,12 +32,11 @@ class ModelService(AbstractDependency, Generic[Model], annotated=False):
|
|
|
29
32
|
async def get(self, ident: int | str, **kwargs: Any) -> Model | None:
|
|
30
33
|
return await self.session.get(self.__model__, ident, **kwargs)
|
|
31
34
|
|
|
32
|
-
async def create(self, model: Model) -> Model:
|
|
33
|
-
return await self.session.add(model)
|
|
34
|
-
|
|
35
35
|
async def create_model(self, **kwargs: Any) -> Model:
|
|
36
36
|
model = self.__model__.model_validate(kwargs)
|
|
37
|
-
|
|
37
|
+
self.session.add(model)
|
|
38
|
+
await self.session.flush()
|
|
39
|
+
return model
|
|
38
40
|
|
|
39
41
|
async def delete(self, model: Model) -> Model:
|
|
40
42
|
return await self.session.delete(model)
|
|
@@ -14,11 +14,13 @@ from fastapi_extra.database.driver import DB, AsyncDB
|
|
|
14
14
|
async def get_async_session(db: AsyncDB) -> AsyncGenerator[AsyncSession, None]:
|
|
15
15
|
async with db.session as session:
|
|
16
16
|
yield session
|
|
17
|
+
await session.commit()
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
def get_session(db: DB) -> Generator[Session, None, None]:
|
|
20
21
|
with db.session as session:
|
|
21
22
|
yield session
|
|
23
|
+
session.commit()
|
|
22
24
|
|
|
23
25
|
|
|
24
26
|
DefaultSession = Annotated[AsyncSession, Depends(get_async_session)]
|
|
@@ -8,7 +8,7 @@ from typing import Annotated, Any, Self
|
|
|
8
8
|
from fastapi.params import Depends
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
class
|
|
11
|
+
class DependencyMetaClass(ABCMeta):
|
|
12
12
|
|
|
13
13
|
def __new__(
|
|
14
14
|
mcs,
|
|
@@ -23,11 +23,11 @@ class AnnotationMetaClass(ABCMeta):
|
|
|
23
23
|
return new_cls
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
class AbstractDependency(metaclass=
|
|
26
|
+
class AbstractDependency(metaclass=DependencyMetaClass, annotated=False):
|
|
27
27
|
__slot__ = ()
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
class
|
|
30
|
+
class AbstractComponent(AbstractDependency, annotated=False):
|
|
31
31
|
__slot__ = ()
|
|
32
32
|
__instance__: Any = None
|
|
33
33
|
|
|
@@ -6,7 +6,7 @@ from typing import Generic, Literal
|
|
|
6
6
|
|
|
7
7
|
from pydantic import BaseModel, Field, model_validator
|
|
8
8
|
|
|
9
|
-
from fastapi_extra.types import C, S
|
|
9
|
+
from fastapi_extra.types import C, S, Schema
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class DataRange(BaseModel, Generic[C]):
|
|
@@ -28,3 +28,10 @@ class ColumnExpression(BaseModel, Generic[S]):
|
|
|
28
28
|
class WhereClause(BaseModel):
|
|
29
29
|
option: Literal["and", "or"] = Field(default="and", title="关系")
|
|
30
30
|
column_clauses: list[ColumnExpression | "WhereClause"]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class Page(BaseModel, Generic[Schema]):
|
|
34
|
+
items: list[Schema] = Field(default_factory=list, title="列表")
|
|
35
|
+
total: int = Field(default=0, title="总量")
|
|
36
|
+
page_num: int = Field(default=0, title="页码")
|
|
37
|
+
page_size: int = Field(default=0, title="单页大小")
|
|
File without changes
|
|
@@ -6,7 +6,7 @@ import datetime
|
|
|
6
6
|
import decimal
|
|
7
7
|
from typing import Annotated, Any, TypeVar, Union
|
|
8
8
|
|
|
9
|
-
from pydantic import PlainSerializer
|
|
9
|
+
from pydantic import BaseModel, PlainSerializer
|
|
10
10
|
from sqlmodel import SQLModel
|
|
11
11
|
|
|
12
12
|
Comparable = Union[int, float, decimal.Decimal, datetime.datetime, datetime.date, datetime.time]
|
|
@@ -17,6 +17,7 @@ T = TypeVar("T", bound=Any)
|
|
|
17
17
|
E = TypeVar("E", bound=Exception)
|
|
18
18
|
C = TypeVar("C", bound=Comparable)
|
|
19
19
|
S = TypeVar("S", bound=Serializable)
|
|
20
|
+
Schema = TypeVar("Schema", bound=BaseModel)
|
|
20
21
|
Model = TypeVar("Model", bound=SQLModel)
|
|
21
22
|
|
|
22
23
|
Cursor = Annotated[
|
|
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
|