Skip to content

Commit

Permalink
Merge pull request #78 from igorbenav/updated-docs
Browse files Browse the repository at this point in the history
Updated docs
  • Loading branch information
igorbenav authored May 8, 2024
2 parents 9d42707 + 3d1544c commit 2e3bdd1
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 4 deletions.
38 changes: 38 additions & 0 deletions docs/advanced/crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,44 @@ item_count = await item_crud.count(
)
```

## Skipping Database Commit

For `create`, `update`, `db_delete` and `delete` methods of `FastCRUD`, you have the option of passing `commit=False` so you don't commit the operations immediately.

```python
from fastcrud import FastCRUD

from .models.item import Item
from .database import session as db

crud_items = FastCRUD(Item)

await crud_items.delete(
db=db,
commit=False,
id=1
)
# this will not actually delete until you run a db.commit()
```

## Unpaginated `get_multi` and `get_multi_joined`

If you pass `None` to `limit` in `get_multi` and `get_multi_joined`, you get the whole unpaginated set of data that matches the filters. Use this with caution.

```python
from fastcrud import FastCRUD

from .models.item import Item
from .database import session as db

crud_items = FastCRUD(Item)
items = await crud_items.get_multi(db=db, limit=None)
# this will return all items in the db
```

!!! CAUTION
Be cautious when returning all the data in your database, and you should almost never allow your API user to do this.

## Using `get_joined` and `get_multi_joined` for multiple models

To facilitate complex data relationships, `get_joined` and `get_multi_joined` can be configured to handle joins with multiple models. This is achieved using the `joins_config` parameter, where you can specify a list of `JoinConfig` instances, each representing a distinct join configuration.
Expand Down
91 changes: 91 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,97 @@ The Changelog documents all notable changes made to FastCRUD. This includes new

___

## [0.12.0] - May 8, 2024

#### Added
- Unpaginated versions of multi-row get methods by @slaarti in #62 🎉
- Nested Join bug fixes
- Dependency handling now working as docs say
- Option to Skip commit in some fastcrud methods
- Docstring example fixes
- `__in` and `__not_in` filters by @JakNowy 🎉
- Fastapi 0.111.0 support

#### Detailed Changes
##### Unpaginated versions of multi-row get methods
Now, if you pass `None` to `limit` in `get_multi` and `get_multi_joined`, you get the whole unpaginated set of data that matches the filters. Use this with caution.

```python
from fastcrud import FastCRUD
from .models.item import Item
from .database import session as db

crud_items = FastCRUD(Item)
items = await crud_items.get_multi(db=db, limit=None)
# this will return all items in the db
```

##### Dependency handling now working as docs say
Now, you may pass dependencies to `crud_router` or `EndpointCreator` as simple functions instead of needing to wrap them in `fastapi.Depends`.

```python
from .dependencies import get_superuser
app.include_router(
crud_router(
session=db,
model=Item,
create_schema=ItemCreate,
update_schema=ItemUpdate,
delete_schema=ItemDelete,
create_deps=[get_superuser],
update_deps=[get_superuser],
delete_deps=[get_superuser],
path="/item",
tags=["item"],
)
)
```

##### Option to Skip commit in some fastcrud methods
For `create`, `update`, `db_delete` and `delete` methods of `FastCRUD`, now you have the option of passing `commit=False` so you don't commit the operations immediately.

```python
from fastcrud import FastCRUD
from .models.item import Item
from .database import session as db

crud_items = FastCRUD(Item)

await crud_items.delete(
db=db,
commit=False,
id=1
)
# this will not actually delete until you run a db.commit()
```

##### `__in` and `__not_in` filters
You may now pass `__in` and `__not_in` to methods that accept advanced queries:

- `__gt`: greater than,
- `__lt`: less than,
- `__gte`: greater than or equal to,
- `__lte`: less than or equal to,
- `__ne`: not equal,
- `__in`: included in [tuple, list or set],
- `__not_in`: not included in [tuple, list or set].

#### What's Changed
- Add unpaginated versions of multi-row get methods (w/tests) by [@slaarti](https://github.com/slaarti) 🎉
- Join fixes
- Dependencies
- Skip commit
- Docstring fix
- feat: filter __in by [@JakNowy](https://github.com/JakNowy) 🎉
- python support for 0.111.0 added
- version bump in pyproject.toml for 0.12.0

#### New Contributors
* [@slaarti](https://github.com/slaarti) made their first contribution in https://github.com/igorbenav/fastcrud/pull/62 🎉

**Full Changelog**: https://github.com/igorbenav/fastcrud/compare/v0.11.1...v0.12.0


## [0.11.1] - Apr 22, 2024

#### Added
Expand Down
12 changes: 8 additions & 4 deletions docs/usage/crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ FastCRUD offers a comprehensive suite of methods for CRUD operations, each desig
```python
create(
db: AsyncSession,
object: CreateSchemaType
object: CreateSchemaType,
commit: bool = True
) -> ModelType
```

Expand Down Expand Up @@ -120,7 +121,7 @@ count = await item_crud.count(db, category="Books")
get_multi(
db: AsyncSession,
offset: int = 0,
limit: int = 100,
limit: Optional[int] = 100,
schema_to_select: Optional[type[BaseModel]] = None,
sort_columns: Optional[Union[str, list[str]]] = None,
sort_orders: Optional[Union[str, list[str]]] = None,
Expand All @@ -144,6 +145,7 @@ update(
db: AsyncSession,
object: Union[UpdateSchemaType, dict[str, Any]],
allow_multiple: bool = False,
commit: bool = True,
**kwargs: Any
) -> None
```
Expand All @@ -162,6 +164,7 @@ delete(
db: AsyncSession,
db_row: Optional[Row] = None,
allow_multiple: bool = False,
commit: bool = True,
**kwargs: Any
) -> None
```
Expand All @@ -179,6 +182,7 @@ await item_crud.delete(db, id=item_id)
db_delete(
db: AsyncSession,
allow_multiple: bool = False,
commit: bool = True,
**kwargs: Any
) -> None
```
Expand All @@ -202,7 +206,7 @@ FastCRUD extends its functionality with advanced methods tailored for complex qu
get_multi(
db: AsyncSession,
offset: int = 0,
limit: int = 100,
limit: Optional[int] = 100,
schema_to_select: Optional[type[BaseModel]] = None,
sort_columns: Optional[Union[str, list[str]]] = None,
sort_orders: Optional[Union[str, list[str]]] = None,
Expand Down Expand Up @@ -265,7 +269,7 @@ get_multi_joined(
join_filters: Optional[dict] = None,
nest_joins: bool = False,
offset: int = 0,
limit: int = 100,
limit: Optional[int] = 100,
sort_columns: Optional[Union[str, list[str]]] = None,
sort_orders: Optional[Union[str, list[str]]] = None,
return_as_model: bool = False,
Expand Down

0 comments on commit 2e3bdd1

Please sign in to comment.