fastapi-extra 0.1.6__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.6"
1
+ __version__ = "0.1.8"
2
2
 
3
3
 
4
4
  from fastapi import FastAPI
@@ -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 AbstractWidget
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(AbstractWidget):
29
+ class RedisCli(AbstractComponent):
30
30
  default_config = _settings.redis
31
31
 
32
32
 
Binary file
@@ -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 AbstractWidget
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(AbstractWidget):
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
- return AsyncEngine(super().engine)
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:
@@ -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)]
@@ -8,7 +8,7 @@ from typing import Annotated, Any, Self
8
8
  from fastapi.params import Depends
9
9
 
10
10
 
11
- class AnnotationMetaClass(ABCMeta):
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=AnnotationMetaClass, annotated=False):
26
+ class AbstractDependency(metaclass=DependencyMetaClass, annotated=False):
27
27
  __slot__ = ()
28
28
 
29
29
 
30
- class AbstractWidget(AbstractDependency, annotated=False):
30
+ class AbstractComponent(AbstractDependency, annotated=False):
31
31
  __slot__ = ()
32
32
  __instance__: Any = None
33
33
 
fastapi_extra/form.py CHANGED
@@ -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="单页大小")
fastapi_extra/py.typed ADDED
File without changes
Binary file
fastapi_extra/types.py CHANGED
@@ -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[
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: fastapi-extra
3
- Version: 0.1.6
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
@@ -0,0 +1,24 @@
1
+ fastapi_extra/__init__.py,sha256=VmSUMSzhrVb6zSyHIl2-mi71gyGRMC9n400N5Gr3aT8,286
2
+ fastapi_extra/cursor.cp312-win_amd64.pyd,sha256=cuMCDVcrH1ltvx1s2zm2PXsbkj20hP-plud-YBKI9D8,57344
3
+ fastapi_extra/dependency.py,sha256=8SgAky63hMa9pnttqRRZMyPAa3BwBMUvFA3ZLH86h44,910
4
+ fastapi_extra/form.py,sha256=Fs9uEDOQThjFroDVTrjWnIGJ107BgXCppIVTymwQLzg,1247
5
+ fastapi_extra/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ fastapi_extra/response.py,sha256=DHvhOSgwot5eBNKuI_jPYxZ5rshZ55Xkg-FNBJlHD1E,9609
7
+ fastapi_extra/routing.cp312-win_amd64.pyd,sha256=6ZHARNFCgL_tlmp6WPSZMR07yrlPe2WAg5jpeXFQTfc,94720
8
+ fastapi_extra/settings.py,sha256=cCcwaper5GiNNoT4gNKqf-iloSOTNnMsiUR0knJx4Mw,1461
9
+ fastapi_extra/types.py,sha256=3z6gUnao6WZL76asZYmex20xfY9mvYA-RbnsxUcui30,819
10
+ fastapi_extra/utils.py,sha256=tsPX3kpF_P5D9Bd3gnlG6rkVsLkv5gbxjml-s6ZL_6I,346
11
+ fastapi_extra/cache/__init__.py,sha256=2bwWFRf6giDo0QiFWEvekQwga9kGTK_9BJdxe32Nru8,126
12
+ fastapi_extra/cache/redis.py,sha256=fLNJfL8V-HYek38WVNwxvW6cnd7rJpcd62vy4O07C44,1592
13
+ fastapi_extra/database/__init__.py,sha256=B59umaoNjDuXyoNh7EYWYEk4xr9tfgVjXsSaOPz3y_Q,328
14
+ fastapi_extra/database/driver.py,sha256=ar_vnfqjpoWjiW5eEdrisyi9CrhfdHtbhAGFxGMKC5E,2223
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
18
+ fastapi_extra/native/cursor.pyx,sha256=bESprFDgk9gGjyPQ4YCSg51dov2WB6s60XrOs3r5-r0,1146
19
+ fastapi_extra/native/routing.pyx,sha256=GrdGAoBospwCpxMHBon5cuRYcz9ifAFSSYa2Ytf49lg,3841
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.0)
2
+ Generator: setuptools (76.0.0)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp312-cp312-win_amd64
5
5
 
@@ -1,23 +0,0 @@
1
- fastapi_extra/__init__.py,sha256=s2AZTyatkiSeY9OmuW6p45fFgX9Dz_nVH0jV8ut52q0,286
2
- fastapi_extra/cursor.cp312-win_amd64.pyd,sha256=IWj0owGMJBYMGeuU-MXPSVRwUCt1hwrlJoqnp97OBNk,57344
3
- fastapi_extra/dependency.py,sha256=Pgl4Y9Mm6JY5pw19w_xJEmnnLkQ9p_K1h1w9lLVHUJQ,907
4
- fastapi_extra/form.py,sha256=LikaJkA16dSRGCqX9K7z2S8-e3SJcMiVXX5nRZU_kVY,957
5
- fastapi_extra/response.py,sha256=DHvhOSgwot5eBNKuI_jPYxZ5rshZ55Xkg-FNBJlHD1E,9609
6
- fastapi_extra/routing.cp312-win_amd64.pyd,sha256=to_HPQbAav7fTQeOYYaFT9zb1b4qdABNkWqQb1uDZdo,94720
7
- fastapi_extra/settings.py,sha256=cCcwaper5GiNNoT4gNKqf-iloSOTNnMsiUR0knJx4Mw,1461
8
- fastapi_extra/types.py,sha256=EUjT9jFryzlazHvWs4m-IfUezmSEvyxwaOGe_vTTBnY,763
9
- fastapi_extra/utils.py,sha256=tsPX3kpF_P5D9Bd3gnlG6rkVsLkv5gbxjml-s6ZL_6I,346
10
- fastapi_extra/cache/__init__.py,sha256=2bwWFRf6giDo0QiFWEvekQwga9kGTK_9BJdxe32Nru8,126
11
- fastapi_extra/cache/redis.py,sha256=N4ntWFNjW1w3OJB64AYSrXbLumPUPK9j2iQcfXxJTC8,1586
12
- fastapi_extra/database/__init__.py,sha256=B59umaoNjDuXyoNh7EYWYEk4xr9tfgVjXsSaOPz3y_Q,328
13
- fastapi_extra/database/driver.py,sha256=VOJxRtXusuRyOJHMHLu18ZYbPQtoIbrkQyyADpHs9cA,2146
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
17
- fastapi_extra/native/cursor.pyx,sha256=bESprFDgk9gGjyPQ4YCSg51dov2WB6s60XrOs3r5-r0,1146
18
- fastapi_extra/native/routing.pyx,sha256=GrdGAoBospwCpxMHBon5cuRYcz9ifAFSSYa2Ytf49lg,3841
19
- fastapi_extra-0.1.6.dist-info/LICENSE,sha256=0vTjHDa3VDsxTT-R-sH6SpYcA2F1hKtbX9ZFZQm-EcU,1516
20
- fastapi_extra-0.1.6.dist-info/METADATA,sha256=U2HYhcc5OTpOGcN5-hOdLXJ4pEIbzqMk5FC5C62lAX0,1348
21
- fastapi_extra-0.1.6.dist-info/WHEEL,sha256=cRmSBGD-cl98KkuHMNqv9Ac9L9_VqTvcBYwpIvxN0cg,101
22
- fastapi_extra-0.1.6.dist-info/top_level.txt,sha256=B7D80bEftE2E-eSd1be2r9BWkLLMZN21dRTWpb4y4Ig,14
23
- fastapi_extra-0.1.6.dist-info/RECORD,,