diff --git a/docs/advanced/crud.md b/docs/advanced/crud.md index 3febfab..6459b2d 100644 --- a/docs/advanced/crud.md +++ b/docs/advanced/crud.md @@ -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. diff --git a/docs/changelog.md b/docs/changelog.md index fd5ecfe..cf93a2c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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 diff --git a/docs/usage/crud.md b/docs/usage/crud.md index f12ea4f..633a279 100644 --- a/docs/usage/crud.md +++ b/docs/usage/crud.md @@ -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 ``` @@ -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, @@ -144,6 +145,7 @@ update( db: AsyncSession, object: Union[UpdateSchemaType, dict[str, Any]], allow_multiple: bool = False, + commit: bool = True, **kwargs: Any ) -> None ``` @@ -162,6 +164,7 @@ delete( db: AsyncSession, db_row: Optional[Row] = None, allow_multiple: bool = False, + commit: bool = True, **kwargs: Any ) -> None ``` @@ -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 ``` @@ -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, @@ -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,