fastapi-extra 0.1.7__cp312-cp312-win_amd64.whl → 0.1.8__cp312-cp312-win_amd64.whl

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/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "0.1.7"
1
+ __version__ = "0.1.8"
2
2
 
3
3
 
4
4
  from fastapi import FastAPI
Binary file
@@ -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)]
fastapi_extra/py.typed ADDED
File without changes
Binary file
@@ -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,9 +1,10 @@
1
- fastapi_extra/__init__.py,sha256=L5-iyVLp59WaMaG4Mu5VxTp4Ymwcgk7o_zrxJkv8VT0,286
2
- fastapi_extra/cursor.cp312-win_amd64.pyd,sha256=Nug4pUw64XsmRotKgNusPmCS59AE-V07NDfGvOKh5ho,57344
1
+ fastapi_extra/__init__.py,sha256=VmSUMSzhrVb6zSyHIl2-mi71gyGRMC9n400N5Gr3aT8,286
2
+ fastapi_extra/cursor.cp312-win_amd64.pyd,sha256=cuMCDVcrH1ltvx1s2zm2PXsbkj20hP-plud-YBKI9D8,57344
3
3
  fastapi_extra/dependency.py,sha256=8SgAky63hMa9pnttqRRZMyPAa3BwBMUvFA3ZLH86h44,910
4
4
  fastapi_extra/form.py,sha256=Fs9uEDOQThjFroDVTrjWnIGJ107BgXCppIVTymwQLzg,1247
5
+ fastapi_extra/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
6
  fastapi_extra/response.py,sha256=DHvhOSgwot5eBNKuI_jPYxZ5rshZ55Xkg-FNBJlHD1E,9609
6
- fastapi_extra/routing.cp312-win_amd64.pyd,sha256=z6xTNU5a8OPh0MRhBEZz7OYTUz3TY4jMvrh15zd83Pw,94720
7
+ fastapi_extra/routing.cp312-win_amd64.pyd,sha256=6ZHARNFCgL_tlmp6WPSZMR07yrlPe2WAg5jpeXFQTfc,94720
7
8
  fastapi_extra/settings.py,sha256=cCcwaper5GiNNoT4gNKqf-iloSOTNnMsiUR0knJx4Mw,1461
8
9
  fastapi_extra/types.py,sha256=3z6gUnao6WZL76asZYmex20xfY9mvYA-RbnsxUcui30,819
9
10
  fastapi_extra/utils.py,sha256=tsPX3kpF_P5D9Bd3gnlG6rkVsLkv5gbxjml-s6ZL_6I,346
@@ -11,13 +12,13 @@ fastapi_extra/cache/__init__.py,sha256=2bwWFRf6giDo0QiFWEvekQwga9kGTK_9BJdxe32Nr
11
12
  fastapi_extra/cache/redis.py,sha256=fLNJfL8V-HYek38WVNwxvW6cnd7rJpcd62vy4O07C44,1592
12
13
  fastapi_extra/database/__init__.py,sha256=B59umaoNjDuXyoNh7EYWYEk4xr9tfgVjXsSaOPz3y_Q,328
13
14
  fastapi_extra/database/driver.py,sha256=ar_vnfqjpoWjiW5eEdrisyi9CrhfdHtbhAGFxGMKC5E,2223
14
- fastapi_extra/database/model.py,sha256=icHh6tnVKYVGl0hNX6pYypTiyGQt3g41geOkjBZTTv4,2467
15
- fastapi_extra/database/service.py,sha256=efDZuz__RqEom-UZHfKQ3rHkxnEYmQocWduVbm3rcy0,1478
16
- fastapi_extra/database/session.py,sha256=XZ5DfkDn4rHHqdJwhRDP87VPDcycxrq6-j_mu4w9Ou0,633
15
+ fastapi_extra/database/model.py,sha256=2ISHT0NUz3-uoqlogxrthzM6GxAfPdghzx1j-lvkSRQ,2451
16
+ fastapi_extra/database/service.py,sha256=TdKlcTQ_WoMqy-kmlYUcFKF7XpyFL8O4vkQ2glZc7P4,1495
17
+ fastapi_extra/database/session.py,sha256=cpKj_NDBSATRCBbmfyYa4v-TKGrMMgRJQCEnkCR153s,691
17
18
  fastapi_extra/native/cursor.pyx,sha256=bESprFDgk9gGjyPQ4YCSg51dov2WB6s60XrOs3r5-r0,1146
18
19
  fastapi_extra/native/routing.pyx,sha256=GrdGAoBospwCpxMHBon5cuRYcz9ifAFSSYa2Ytf49lg,3841
19
- fastapi_extra-0.1.7.dist-info/LICENSE,sha256=0vTjHDa3VDsxTT-R-sH6SpYcA2F1hKtbX9ZFZQm-EcU,1516
20
- fastapi_extra-0.1.7.dist-info/METADATA,sha256=NBcCEjLJhFJs1K1PuBRxp-V2gC9efCXWdRkuUr-7-xU,1348
21
- fastapi_extra-0.1.7.dist-info/WHEEL,sha256=GNSMLKsI4JcODC8iIUwfCC2mP5aj3pHj8CNqlVH-mAI,101
22
- fastapi_extra-0.1.7.dist-info/top_level.txt,sha256=B7D80bEftE2E-eSd1be2r9BWkLLMZN21dRTWpb4y4Ig,14
23
- fastapi_extra-0.1.7.dist-info/RECORD,,
20
+ fastapi_extra-0.1.8.dist-info/LICENSE,sha256=0vTjHDa3VDsxTT-R-sH6SpYcA2F1hKtbX9ZFZQm-EcU,1516
21
+ fastapi_extra-0.1.8.dist-info/METADATA,sha256=Mg9fJV2_mAo_PZXq3JCq_Mv9t69noysoU7HmNnN1wzA,1348
22
+ fastapi_extra-0.1.8.dist-info/WHEEL,sha256=A8mRFNvJcDL8dRPZ6k2ICKEOXwE8pzYFXYxEla0rR0g,101
23
+ fastapi_extra-0.1.8.dist-info/top_level.txt,sha256=B7D80bEftE2E-eSd1be2r9BWkLLMZN21dRTWpb4y4Ig,14
24
+ fastapi_extra-0.1.8.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.2)
2
+ Generator: setuptools (76.0.0)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp312-cp312-win_amd64
5
5