Skip to content

Commit

Permalink
docs updated, version updated to 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
igorbenav committed Feb 11, 2024
1 parent 095d945 commit e39e732
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
35 changes: 33 additions & 2 deletions docs/advanced/endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ class MyModel(Base):
archived_at = Column(DateTime) # Custom timestamp column for soft delete
```

### Using `EndpointCreator` and `crud_router` with Custom Soft Delete Columns
### Using `EndpointCreator` and `crud_router` with Custom Soft Delete or Update Columns

When initializing `crud_router` or creating a custom `EndpointCreator`, you can pass the names of your custom soft delete columns through the `FastCRUD` initialization. This informs FastCRUD which columns to check and update for soft deletion operations.

Here's an example of using `crud_router` with custom soft delete columns:

```python
```python hl_lines="11-14 20"
from fastapi import FastAPI
from fastcrud import FastCRUD, crud_router
from sqlalchemy.ext.asyncio import AsyncSession
Expand Down Expand Up @@ -227,6 +227,37 @@ app.include_router(crud_router(
))
```

You may also directly pass the names of the columns to crud_router or EndpointCreator:

```python hl_lines="9 10"
app.include_router(endpoint_creator(
session=async_session,
model=MyModel,
create_schema=CreateMyModelSchema,
update_schema=UpdateMyModelSchema,
delete_schema=DeleteMyModelSchema,
path="/mymodel",
tags=["MyModel"],
is_deleted_column='archived',
deleted_at_column='archived_at'
))
```

You can also customize your `updated_at` column:

```python hl_lines="9"
app.include_router(endpoint_creator(
session=async_session,
model=MyModel,
create_schema=CreateMyModelSchema,
update_schema=UpdateMyModelSchema,
delete_schema=DeleteMyModelSchema,
path="/mymodel",
tags=["MyModel"],
updated_at_column='date_updated'
))
```

This setup ensures that the soft delete functionality within your application utilizes the `archived` and `archived_at` columns for marking records as deleted, rather than the default `is_deleted` and `deleted_at` fields.

By specifying custom column names for soft deletion, you can adapt FastCRUD to fit the design of your database models, providing a flexible solution for handling deleted records in a way that best suits your application's needs.
Expand Down
6 changes: 2 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False
Use `crud_router` and include it in your `FastAPI` application

```python
from fastcrud import FastCRUD, crud_router
from fastcrud import crud_router

async def get_session() -> AsyncGenerator[AsyncSession, None]:
async with async_session() as session:
Expand All @@ -86,7 +86,6 @@ app = FastAPI(lifespan=lifespan)
item_router = crud_router(
session=get_session,
model=Item,
crud=FastCRUD(Item),
create_schema=ItemSchema,
update_schema=ItemSchema,
path="/items",
Expand Down Expand Up @@ -171,7 +170,7 @@ class ItemUpdateSchema(BaseModel):
from typing import AsyncGenerator

from fastapi import FastAPI
from fastcrud import FastCRUD, crud_router
from fastcrud import crud_router
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker

Expand Down Expand Up @@ -201,7 +200,6 @@ crud = FastCRUD(Item)
item_router = crud_router(
session=get_session,
model=Item,
crud=crud,
create_schema=ItemCreateSchema,
update_schema=ItemUpdateSchema,
path="/items",
Expand Down
5 changes: 2 additions & 3 deletions docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False

Use `crud_router` and include it in your `FastAPI` application

```python title="main.py" hl_lines="17-25 27"
from fastcrud import FastCRUD, crud_router
```python title="main.py" hl_lines="17-24 26"
from fastcrud import crud_router

# Database session dependency
async def get_session() -> AsyncGenerator[AsyncSession, None]:
Expand All @@ -102,7 +102,6 @@ app = FastAPI(lifespan=lifespan)
item_router = crud_router(
session=session,
model=Item,
crud=FastCRUD(Item),
create_schema=ItemSchema,
update_schema=ItemSchema,
path="/items",
Expand Down
5 changes: 2 additions & 3 deletions docs/sqlmodel.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False

Use `crud_router` and include it in your `FastAPI` application

```python title="main.py" hl_lines="17-25 27"
from fastcrud import FastCRUD, crud_router
```python title="main.py" hl_lines="17-24 26"
from fastcrud import crud_router

# Database session dependency
async def get_session() -> AsyncGenerator[AsyncSession, None]:
Expand All @@ -86,7 +86,6 @@ app = FastAPI(lifespan=lifespan)
item_router = crud_router(
session=get_session,
model=Item,
crud=FastCRUD(Item),
create_schema=ItemSchema,
update_schema=ItemSchema,
path="/items",
Expand Down
7 changes: 1 addition & 6 deletions docs/usage/endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ItemUpdateSchema(BaseModel):

### Step 2: Set Up FastAPI and FastCRUD

Next, set up your FastAPI application and FastCRUD instances. This involves configuring the database connection and creating a CRUD instance for your model.
Next, set up your FastAPI application, you can optionally set up a custom FastCRUD instance as well. This involves configuring the database connection.

```python
from typing import AsyncGenerator
Expand Down Expand Up @@ -71,9 +71,6 @@ async def lifespan(app: FastAPI):

# FastAPI app
app = FastAPI(lifespan=lifespan)

# CRUD operations setup
crud = FastCRUD(Item)
```

### Step 3: Use `crud_router` to Create Endpoints
Expand All @@ -83,7 +80,6 @@ crud = FastCRUD(Item)
item_router = crud_router(
session=get_session,
model=Item,
crud=crud,
create_schema=ItemCreateSchema,
update_schema=ItemUpdateSchema,
path="/items",
Expand Down Expand Up @@ -176,7 +172,6 @@ from fastcrud import EndpointCreator
endpoint_creator = EndpointCreator(
session=get_session,
model=YourModel,
crud=your_crud_instance,
create_schema=YourCreateSchema,
update_schema=YourUpdateSchema,
delete_schema=YourDeleteSchema,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fastcrud"
version = "0.5.0"
version = "0.6.0"
description = "FastCRUD is a Python package for FastAPI, offering robust async CRUD operations and flexible endpoint creation utilities."
authors = ["Igor Benav <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit e39e732

Please sign in to comment.