Skip to content

Commit

Permalink
Merge pull request #133 from slaarti/models_backfill
Browse files Browse the repository at this point in the history
Backfill docstring fixes.
  • Loading branch information
igorbenav authored Jul 26, 2024
2 parents 35eb387 + 09aebbc commit 61750f1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions fastcrud/crud/fast_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,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)
Expand Down
12 changes: 8 additions & 4 deletions fastcrud/endpoint/crud_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ def get_current_user(token: str = Depends(oauth2_scheme)):
```
With Selective CRUD Methods:
```python
CRUDMyModel = FastCRUD[
MyModelCRUD = FastCRUD[
MyModel,
CreateMyModelSchema,
UpdateMyModelSchema,
Expand All @@ -285,14 +286,15 @@ 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"],
)
```
Using a Custom `EndpointCreator`:
```python
class CustomEndpointCreator(EndpointCreator):
def _custom_route(self):
Expand All @@ -315,7 +317,7 @@ async def add_routes_to_router(self, ...):
# Other parameters as needed
)
CRUDMyModel = FastCRUD[
MyModelCRUD = FastCRUD[
MyModel,
CreateMyModelSchema,
UpdateMyModelSchema,
Expand All @@ -327,7 +329,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,
Expand Down Expand Up @@ -358,6 +360,7 @@ async def add_routes_to_router(self, ...):
```
Using `FilterConfig` with `dict`:
```python
from fastapi import FastAPI
from fastcrud import crud_router
Expand Down Expand Up @@ -386,6 +389,7 @@ async def add_routes_to_router(self, ...):
```
Using `FilterConfig` with keyword arguments:
```python
from fastapi import FastAPI
from fastcrud import crud_router
Expand Down
14 changes: 12 additions & 2 deletions fastcrud/endpoint/endpoint_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class EndpointCreator:
```
With Custom Dependencies:
```python
from fastapi.security import OAuth2PasswordBearer
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -148,6 +152,7 @@ def get_current_user(token: str = Depends(oauth2_scheme)):
```
Customizing Endpoint Names:
```python
endpoint_creator = EndpointCreator(
session=async_session,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -501,6 +510,7 @@ def add_routes_to_router(
```
With Custom Dependencies and Selective Endpoints:
```python
def get_current_user(...):
...
Expand Down

0 comments on commit 61750f1

Please sign in to comment.