diff --git a/fastcrud/crud/fast_crud.py b/fastcrud/crud/fast_crud.py index 72e3a54..e106256 100644 --- a/fastcrud/crud/fast_crud.py +++ b/fastcrud/crud/fast_crud.py @@ -159,7 +159,9 @@ class FastCRUD( Example 4: Cursor Pagination ---------------------------- + Implement cursor-based pagination for efficient data retrieval in large datasets. + ```python class Comment(Base): id = Column(Integer, primary_key=True) diff --git a/fastcrud/endpoint/crud_router.py b/fastcrud/endpoint/crud_router.py index c685dcd..53ad50d 100644 --- a/fastcrud/endpoint/crud_router.py +++ b/fastcrud/endpoint/crud_router.py @@ -185,8 +185,9 @@ def get_current_user(token: str = Depends(oauth2_scheme)): ``` With Selective CRUD Methods: + ```python - CRUDMyModel = FastCRUD[ + MyModelCRUD = FastCRUD[ MyModel, CreateMyModelSchema, UpdateMyModelSchema, @@ -199,7 +200,7 @@ def get_current_user(token: str = Depends(oauth2_scheme)): model=MyModel, create_schema=CreateMyModelSchema, update_schema=UpdateMyModelSchema, - crud=CRUDMyModel(MyModel), + crud=MyModelCRUD(MyModel), path="/mymodel", tags=["MyModel"], included_methods=["create", "read"], @@ -207,6 +208,7 @@ def get_current_user(token: str = Depends(oauth2_scheme)): ``` Using a Custom `EndpointCreator`: + ```python class CustomEndpointCreator(EndpointCreator): def _custom_route(self): @@ -229,7 +231,7 @@ async def add_routes_to_router(self, ...): # Other parameters as needed ) - CRUDMyModel = FastCRUD[ + MyModelCRUD = FastCRUD[ MyModel, CreateMyModelSchema, UpdateMyModelSchema, @@ -241,7 +243,7 @@ async def add_routes_to_router(self, ...): model=MyModel, create_schema=CreateMyModelSchema, update_schema=UpdateMyModelSchema, - crud=CRUDMyModel(MyModel), + crud=MyModelCRUD(MyModel), path="/mymodel", tags=["MyModel"], endpoint_creator=CustomEndpointCreator, @@ -272,6 +274,7 @@ async def add_routes_to_router(self, ...): ``` Using `FilterConfig` with `dict`: + ```python from fastapi import FastAPI from fastcrud import crud_router @@ -300,6 +303,7 @@ async def add_routes_to_router(self, ...): ``` Using `FilterConfig` with keyword arguments: + ```python from fastapi import FastAPI from fastcrud import crud_router diff --git a/fastcrud/endpoint/endpoint_creator.py b/fastcrud/endpoint/endpoint_creator.py index e4604cc..8dd5d82 100644 --- a/fastcrud/endpoint/endpoint_creator.py +++ b/fastcrud/endpoint/endpoint_creator.py @@ -101,6 +101,7 @@ class EndpointCreator: ``` With Custom Dependencies: + ```python from fastapi.security import OAuth2PasswordBearer @@ -116,6 +117,7 @@ def get_current_user(token: str = Depends(oauth2_scheme)): ``` Selective Endpoint Creation (inclusion): + ```python # Only create 'create' and 'read' endpoints endpoint_creator.add_routes_to_router( @@ -124,6 +126,7 @@ def get_current_user(token: str = Depends(oauth2_scheme)): ``` Selective Endpoint Creation (deletion): + ```python # Create all but 'update' and 'delete' endpoints endpoint_creator.add_routes_to_router( @@ -132,10 +135,11 @@ def get_current_user(token: str = Depends(oauth2_scheme)): ``` Integrating with Multiple Models: + ```python - # Assuming definitions for OtherModel, CRUDOtherModel, etc. + # Assuming definitions for OtherModel, OtherModelCRUD, etc. - other_model_crud = CRUDOtherModel(OtherModel) + other_model_crud = OtherModelCRUD(OtherModel) other_endpoint_creator = EndpointCreator( session=async_session, model=OtherModel, @@ -148,6 +152,7 @@ def get_current_user(token: str = Depends(oauth2_scheme)): ``` Customizing Endpoint Names: + ```python endpoint_creator = EndpointCreator( session=async_session, @@ -167,6 +172,7 @@ def get_current_user(token: str = Depends(oauth2_scheme)): ``` Using `filter_config` with `dict`: + ```python from fastapi import FastAPI from fastcrud import EndpointCreator, FilterConfig @@ -196,6 +202,7 @@ def get_current_user(token: str = Depends(oauth2_scheme)): ``` Using `filter_config` with keyword arguments: + ```python from fastapi import FastAPI from fastcrud import EndpointCreator, FilterConfig @@ -485,6 +492,7 @@ def add_routes_to_router( Examples: Selective Endpoint Creation: + ```python # Only create 'create' and 'read' endpoints endpoint_creator.add_routes_to_router( @@ -493,6 +501,7 @@ def add_routes_to_router( ``` Excluding Specific Endpoints: + ```python # Create all endpoints except 'delete' and 'db_delete' endpoint_creator.add_routes_to_router( @@ -501,6 +510,7 @@ def add_routes_to_router( ``` With Custom Dependencies and Selective Endpoints: + ```python def get_current_user(...): ...