The new version of the project includes numerous improvements and new features, mainly focused on supporting foreign key relationships between models, enhancing code organization, and increasing test coverage. Here are the main changes:
New Features
- Introduced support for `CASCADE`, `RESTRICT`, `SET DEFAULT`, `SET NULL` and `NO ACTION` on_delete actions for foreign key constraints.
Code Refactoring
- Refactored foreign key handling in the `DBModel` class for better readability and maintainability.
- Simplified logic for handling foreign key models in the `_prepare_values_to_insert` method.
- Improved foreign key constraint generation logic for better readability and maintainability.
Tests
- Updated the `db_cursor` fixture in `conftest.py` to use the `get_cursor` function and properly close the connection.
- Added test cases for deleting objects with foreign keys set to `CASCADE`, `RESTRICT`, `SET DEFAULT`, `SET NULL` and `NO ACTION`
Fixes
- Updated the `execute_sql` function in `sql_utils.py` to use the `get_cursor` function, ensuring foreign key support is enabled.
Documentation
- Added documentation in `README.md` on how to define foreign keys with custom `on_delete` actions.
- Provided examples in `README.md` on defining foreign keys with different `on_delete` options such as `SET_NULL`, `RESTRICT`, `SET_DEFAULT`, `NO_ACTION`, and `CASCADE`.
In summary, the new version brings advanced support for foreign key relationships, improved code organization, and comprehensive tests for key methods.
Features and Roadmap
- [x] Define table schema using Pydantic models
- [x] Basic CRUD operations
- [x] Save data to the database
- [x] Read data from the database
- [x] Update data in the database
- [x] Delete data from the database
- [ ] Relationships between tables
- [x] One-to-many
- [x] Create a tables with a foreign key
- [x] Save data with a foreign key
- [x] Read data with a foreign key
- [x] Update data with a foreign key
- [x] Delete data with a foreign key
- [X] Cascade
- [x] Set null
- [x] Restrict
- [x] Set default
- [x] No action
- [ ] One-to-one
- [ ] Many-to-many
- [ ] Custom primary key
- [ ] Bulk operations (save, update, delete)
- [ ] Migrations
**Full Changelog**: https://github.com/SpaceShaman/ORMagic/compare/v0.2.1...v0.3.0