fastapi-extra 0.1.7__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.
Files changed (27) hide show
  1. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/PKG-INFO +1 -1
  2. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/__init__.py +1 -1
  3. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/database/model.py +1 -1
  4. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/database/service.py +9 -7
  5. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/database/session.py +2 -0
  6. fastapi_extra-0.1.8/fastapi_extra/py.typed +0 -0
  7. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra.egg-info/PKG-INFO +1 -1
  8. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra.egg-info/SOURCES.txt +1 -0
  9. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/LICENSE +0 -0
  10. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/README.rst +0 -0
  11. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/cache/__init__.py +0 -0
  12. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/cache/redis.py +0 -0
  13. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/database/__init__.py +0 -0
  14. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/database/driver.py +0 -0
  15. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/dependency.py +0 -0
  16. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/form.py +0 -0
  17. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/native/cursor.pyx +0 -0
  18. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/native/routing.pyx +0 -0
  19. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/response.py +0 -0
  20. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/settings.py +0 -0
  21. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/types.py +0 -0
  22. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra/utils.py +0 -0
  23. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra.egg-info/dependency_links.txt +0 -0
  24. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra.egg-info/requires.txt +0 -0
  25. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/fastapi_extra.egg-info/top_level.txt +0 -0
  26. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/pyproject.toml +0 -0
  27. {fastapi_extra-0.1.7 → fastapi_extra-0.1.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: fastapi-extra
3
- Version: 0.1.7
3
+ Version: 0.1.8
4
4
  Summary: extra package for fastapi.
5
5
  Author-email: Ziyan Yin <408856732@qq.com>
6
6
  License: BSD-3-Clause
@@ -1,4 +1,4 @@
1
- __version__ = "0.1.7"
1
+ __version__ = "0.1.8"
2
2
 
3
3
 
4
4
  from fastapi import FastAPI
@@ -15,7 +15,7 @@ from fastapi_extra.utils import get_machine_seed
15
15
 
16
16
  class AutoPK(SQLModel):
17
17
  id: int | None = Field(
18
- default_factory=lambda: None,
18
+ default=None,
19
19
  title="ID",
20
20
  primary_key=True,
21
21
  sa_type=BigInteger,
@@ -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__: SQLModel
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
- cls.__model__ = item
24
- return cls
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
- return self.create(model)
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)]
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: fastapi-extra
3
- Version: 0.1.7
3
+ Version: 0.1.8
4
4
  Summary: extra package for fastapi.
5
5
  Author-email: Ziyan Yin <408856732@qq.com>
6
6
  License: BSD-3-Clause
@@ -4,6 +4,7 @@ pyproject.toml
4
4
  fastapi_extra/__init__.py
5
5
  fastapi_extra/dependency.py
6
6
  fastapi_extra/form.py
7
+ fastapi_extra/py.typed
7
8
  fastapi_extra/response.py
8
9
  fastapi_extra/settings.py
9
10
  fastapi_extra/types.py
File without changes
File without changes
File without changes