|
5 | 5 | The Changelog documents all notable changes made to FastCRUD. This includes new features, bug fixes, and improvements. It's organized by version and date, providing a clear history of the library's development.
|
6 | 6 |
|
7 | 7 | ___
|
| 8 | +## [0.14.0] - Jul 29, 2024 |
| 9 | + |
| 10 | +#### Added |
| 11 | +- Type-checking support for SQLModel types by @kdcokenny 🚀 |
| 12 | +- Returning clause to update operations by @feluelle |
| 13 | +- Upsert_multi functionality by @feluelle |
| 14 | +- Simplified endpoint configurations by @JakNowy, streamlining path generation and merging pagination functionalities into a unified `_read_items` endpoint, promoting more efficient API structure and usage. Details in https://github.com/igorbenav/fastcrud/pull/105 |
| 15 | + |
| 16 | +#### Improved |
| 17 | +- Comprehensive tests for paginated retrieval of items, maintaining 100% coverage |
| 18 | +- Docker client check before running tests that require Docker by @feluelle |
| 19 | + |
| 20 | +#### Fixed |
| 21 | +- Vulnerability associated with an outdated cryptography package |
| 22 | +- Return type inconsistency in async session fixtures by @slaarti |
| 23 | + |
| 24 | +#### Documentation Updates |
| 25 | +- Cleanup of documentation formatting by @slaarti |
| 26 | +- Replacement of the Contributing section in docs with an include to file in repo root by @slaarti |
| 27 | +- Correction of links to advanced filters in docstrings by @slaarti |
| 28 | +- Backfill of docstring fixes across various modules by @slaarti |
| 29 | +- Enhanced filter documentation with new AND and OR clause examples, making complex queries more accessible and understandable. |
| 30 | + |
| 31 | +#### Models and Schemas Enhancements |
| 32 | +- Introduction of simple and one-off models (Batch 1) by @slaarti |
| 33 | +- Expansion to include models and schemas for Customers, Products, and Orders (Batch 2) by @slaarti |
| 34 | + |
| 35 | +#### Code Refinements |
| 36 | +- Resolution of missing type specifications in kwargs by @slaarti |
| 37 | +- Collapsed space adjustments for models/schemas in `fast_crud.py` by @slaarti |
| 38 | + |
| 39 | +#### Warnings |
| 40 | +- **Deprecation Notice**: `_read_paginated` endpoint is set to be deprecated and merged into `_read_items`. Users are encouraged to transition to the latter, utilizing optional pagination parameters. Full details and usage instructions provided to ensure a smooth transition. |
| 41 | +- **Future Changes Alert**: Default endpoint names in `EndpointCreator` are anticipated to be set to empty strings in a forthcoming major release, aligning with simplification efforts. Refer to https://github.com/igorbenav/fastcrud/issues/67 for more information. |
| 42 | + |
| 43 | +#### Detailed Changes |
| 44 | +___ |
| 45 | +##### Simplified Endpoint Configurations |
| 46 | + |
| 47 | +In an effort to streamline FastCRUD’s API, we have reconfigured endpoint paths to avoid redundancy (great work by @JakNowy). This change allows developers to specify empty strings for endpoint names in the `crud_router` setup, which prevents the generation of unnecessary `//` in the paths. The following configurations illustrate how endpoints can now be defined more succinctly: |
| 48 | + |
| 49 | +```python |
| 50 | +endpoint_names = { |
| 51 | + "create": "", |
| 52 | + "read": "", |
| 53 | + "update": "", |
| 54 | + "delete": "", |
| 55 | + "db_delete": "", |
| 56 | + "read_multi": "", |
| 57 | + "read_paginated": "get_paginated", |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +Moreover, the `_read_paginated` logic has been integrated into the `_read_items` endpoint. This integration means that pagination can now be controlled via `page` and `items_per_page` query parameters, offering a unified method for both paginated and non-paginated reads: |
| 62 | + |
| 63 | +- **Paginated read example**: |
| 64 | + |
| 65 | +```bash |
| 66 | +curl -X 'GET' \ |
| 67 | + 'http://localhost:8000/users/get_multi?page=2&itemsPerPage=10' \ |
| 68 | + -H 'accept: application/json' |
| 69 | +``` |
| 70 | + |
| 71 | +- **Non-paginated read example**: |
| 72 | + |
| 73 | +```bash |
| 74 | +curl -X 'GET' \ |
| 75 | + 'http://localhost:8000/users/get_multi?offset=0&limit=100' \ |
| 76 | + -H 'accept: application/json' |
| 77 | +``` |
| 78 | + |
| 79 | +###### Warnings |
| 80 | + |
| 81 | +- **Deprecation Warning**: The `_read_paginated` endpoint is slated for deprecation. Developers should transition to using `_read_items` with the relevant pagination parameters. |
| 82 | +- **Configuration Change Alert**: In a future major release, default endpoint names in `EndpointCreator` will be empty strings by default, as discussed in [Issue #67](https://github.com/igorbenav/fastcrud/issues/67). |
| 83 | + |
| 84 | +###### Advanced Filters Documentation Update |
| 85 | + |
| 86 | +Documentation for advanced filters has been expanded to include comprehensive examples of AND and OR clauses, enhancing the utility and accessibility of complex query constructions. |
| 87 | + |
| 88 | +- **OR clause example**: |
| 89 | + |
| 90 | +```python |
| 91 | +# Fetch items priced under $5 or above $20 |
| 92 | +items = await item_crud.get_multi( |
| 93 | + db=db, |
| 94 | + price__or={'lt': 5, 'gt': 20}, |
| 95 | +) |
| 96 | +``` |
| 97 | + |
| 98 | +- **AND clause example**: |
| 99 | + |
| 100 | +```python |
| 101 | +# Fetch items priced under $20 and over 2 years of warranty |
| 102 | +items = await item_crud.get_multi( |
| 103 | + db=db, |
| 104 | + price__lt=20, |
| 105 | + warranty_years__gt=2, |
| 106 | +) |
| 107 | +``` |
| 108 | + |
| 109 | +___ |
| 110 | +##### Returning Clauses in Update Operations |
| 111 | + |
| 112 | +###### Description |
| 113 | +Users can now retrieve updated records immediately following an update operation. This feature streamlines the process, reducing the need for subsequent retrieval calls and increasing efficiency. |
| 114 | + |
| 115 | +###### Changes |
| 116 | +- **Return Columns**: Specify the columns to be returned after the update via the `return_columns` argument. |
| 117 | +- **Schema Selection**: Optionally select a Pydantic schema to format the returned data using the `schema_to_select` argument. |
| 118 | +- **Return as Model**: Decide if the returned data should be converted into a model using the `return_as_model` argument. |
| 119 | +- **Single or None**: Utilize the `one_or_none` argument to ensure that either a single record is returned or none, in case the conditions do not match any records. |
| 120 | + |
| 121 | +These additions are aligned with existing CRUD API functions, enhancing consistency across the library and making the new features intuitive for users. |
| 122 | + |
| 123 | +###### Usage Example |
| 124 | + |
| 125 | +###### Returning Updated Fields |
| 126 | + |
| 127 | +```python |
| 128 | +from fastcrud import FastCRUD |
| 129 | +from .models.item import Item |
| 130 | +from .database import session as db |
| 131 | + |
| 132 | +crud_items = FastCRUD(Item) |
| 133 | +updated_item = await crud_items.update( |
| 134 | + db=db, |
| 135 | + object={"price": 9.99}, |
| 136 | + price__lt=10, |
| 137 | + return_columns=["price"] |
| 138 | +) |
| 139 | +# This returns the updated price of the item directly. |
| 140 | +``` |
| 141 | + |
| 142 | +###### Returning Data as a Model |
| 143 | + |
| 144 | +```python |
| 145 | +from fastcrud import FastCRUD |
| 146 | +from .models.item import Item |
| 147 | +from .schemas.item import ItemSchema |
| 148 | +from .database import session as db |
| 149 | + |
| 150 | +crud_items = FastCRUD(Item) |
| 151 | +updated_item_schema = await crud_items.update( |
| 152 | + db=db, |
| 153 | + object={"price": 9.99}, |
| 154 | + price__lt=10, |
| 155 | + schema_to_select=ItemSchema, |
| 156 | + return_as_model=True |
| 157 | +) |
| 158 | +# This returns the updated item data formatted as an ItemSchema model. |
| 159 | +``` |
| 160 | + |
| 161 | +___ |
| 162 | +##### Bulk Upsert Operations with `upsert_multi` |
| 163 | + |
| 164 | +The `upsert_multi` method provides the ability to perform bulk upsert operations, which are optimized for different SQL dialects. |
| 165 | + |
| 166 | +###### Changes |
| 167 | +- **Dialect-Optimized SQL**: Uses the most efficient SQL commands based on the database's SQL dialect. |
| 168 | +- **Support for Multiple Dialects**: Includes custom implementations for PostgreSQL, SQLite, and MySQL, with appropriate handling for each's capabilities and limitations. |
| 169 | + |
| 170 | +###### Usage Example |
| 171 | + |
| 172 | +###### Upserting Multiple Records |
| 173 | + |
| 174 | +```python |
| 175 | +from fastcrud import FastCRUD |
| 176 | +from .models.item import Item |
| 177 | +from .schemas.item import ItemCreateSchema, ItemSchema |
| 178 | +from .database import session as db |
| 179 | + |
| 180 | +crud_items = FastCRUD(Item) |
| 181 | +items = await crud_items.upsert_multi( |
| 182 | + db=db, |
| 183 | + instances=[ |
| 184 | + ItemCreateSchema(price=9.99), |
| 185 | + ], |
| 186 | + schema_to_select=ItemSchema, |
| 187 | + return_as_model=True, |
| 188 | +) |
| 189 | +# This will return the upserted data in the form of ItemSchema. |
| 190 | +``` |
| 191 | + |
| 192 | +###### Implementation Details |
| 193 | + |
| 194 | +`upsert_multi` handles different database dialects: |
| 195 | +- **PostgreSQL**: Uses `ON CONFLICT DO UPDATE`. |
| 196 | +- **SQLite**: Utilizes `ON CONFLICT DO UPDATE`. |
| 197 | +- **MySQL**: Implements `ON DUPLICATE KEY UPDATE`. |
| 198 | + |
| 199 | +###### Notes |
| 200 | +- MySQL and MariaDB do not support certain advanced features used in other dialects, such as returning values directly after an insert or update operation. This limitation is clearly documented to prevent misuse. |
| 201 | + |
| 202 | +#### New Contributors |
| 203 | +- @kdcokenny made their first contribution 🌟 |
| 204 | +- @feluelle made their first contribution 🌟 |
| 205 | + |
| 206 | +**Full Changelog**: [View the full changelog](https://github.com/igorbenav/fastcrud/compare/v0.13.1...v0.14.0) |
| 207 | + |
| 208 | + |
8 | 209 | ## [0.13.1] - Jun 22, 2024
|
9 | 210 |
|
10 | 211 | #### Added
|
|
0 commit comments