Releases: SpaceShaman/ORMagic
v0.4.0
The new version of the project introduces several improvements and new features, focusing on defining unique constraints, enhancing database table management, and improving documentation. Here are the main changes:
New Features
- Added support for defining unique constraints in database table columns.
- Introduced the
drop_tablemethod in theDBModelclass to drop a table from the database.
Tests
- Added a test case in
test_save.pyto ensure that the uniqueness constraint work properly. - Added a test case for the
drop_tablemethod intest_remove_table.py.
Documentation
- Updated
README.mdto include information on defining unique constraints. - Added instructions for deleting and updating tables in the
README.md. - Updated Features and Roadmap checklist
Continuous Integration
- Updated the
coverage.ymlto specify coverage for theormagicpackage in the pytest command.
In summary, the new version brings support for unique constraints, new methods for managing database tables, and comprehensive updates to documentation and test coverage.
Features and Roadmap
- Define table schema using Pydantic models
- Basic CRUD operations
- Save data to the database
- Read data from the database
- Update data in the database
- Delete data from the database
- Relationships between tables
- One-to-many
- Create a tables with a foreign key
- Save data with a foreign key
- Read data with a foreign key
- Update data with a foreign key
- Delete data with a foreign key
- Cascade
- Set null
- Restrict
- Set default
- No action
- One-to-one
- Many-to-many
- One-to-many
- Unique constraints
- Remove table
- Update table schema
- Filter data and retrieve multiple records
- Custom primary key
- Bulk operations (save, update, delete)
- Migrations
Full Changelog: v0.3.0...v0.4.0
v0.3.0
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 NULLandNO ACTIONon_delete actions for foreign key constraints.
Code Refactoring
- Refactored foreign key handling in the
DBModelclass for better readability and maintainability. - Simplified logic for handling foreign key models in the
_prepare_values_to_insertmethod. - Improved foreign key constraint generation logic for better readability and maintainability.
Tests
- Updated the
db_cursorfixture inconftest.pyto use theget_cursorfunction and properly close the connection. - Added test cases for deleting objects with foreign keys set to
CASCADE,RESTRICT,SET DEFAULT,SET NULLandNO ACTION
Fixes
- Updated the
execute_sqlfunction insql_utils.pyto use theget_cursorfunction, ensuring foreign key support is enabled.
Documentation
- Added documentation in
README.mdon how to define foreign keys with customon_deleteactions. - Provided examples in
README.mdon defining foreign keys with differenton_deleteoptions such asSET_NULL,RESTRICT,SET_DEFAULT,NO_ACTION, andCASCADE.
In summary, the new version brings advanced support for foreign key relationships, improved code organization, and comprehensive tests for key methods.
Features and Roadmap
- Define table schema using Pydantic models
- Basic CRUD operations
- Save data to the database
- Read data from the database
- Update data in the database
- Delete data from the database
- Relationships between tables
- One-to-many
- Create a tables with a foreign key
- Save data with a foreign key
- Read data with a foreign key
- Update data with a foreign key
- Delete data with a foreign key
- Cascade
- Set null
- Restrict
- Set default
- No action
- One-to-one
- Many-to-many
- One-to-many
- Custom primary key
- Bulk operations (save, update, delete)
- Migrations
Full Changelog: v0.2.1...v0.3.0
v0.2.1
The new version of the project includes several improvements and new features, primarily focused on enhancing code organization, supporting more complex relationships between models, and increasing test coverage. Here are the main changes:
Code Refactoring
- Extracted common logic into separate methods for better readability and organization.
- Updated the
_create_instance_from_datamethod signature to accept a tuple parameter instead of any type.
New Features
- Added support for updating model fields with nested objects when performing database updates.
- Introduced support for optional foreign key fields in the
DBModelclass.
Tests
- Added unit tests for the
_create_instance_from_dataand_prepare_fields_to_updatemethods, including tests for handling foreign key values. - Created a new test file
test_prepare_values_to_insert.pyto test the_prepare_values_to_insertmethod. - Added tests to ensure the correct creation of instances with foreign key relationships and tests for getting and saving objects with optional foreign key fields set or not set.
Fixes
- Fixed handling of cases where the value is
Nonefor foreign key fields.
Miscellaneous
- Deleted the unnecessary test file
test_.py. - Added type-ignore comments to assertions in tests to ensure compatibility with optional foreign key fields.
In summary, the new version brings better code organization, new features for handling nested objects and optional foreign key fields, and comprehensive unit tests for key methods.
Features and Roadmap
- Define table schema using Pydantic models
- Basic CRUD operations
- Save data to the database
- Read data from the database
- Update data in the database
- Delete data from the database
- Relationships between tables
- One-to-many
- Create a tables with a foreign key
- Save data with a foreign key
- Read data with a foreign key
- Update data with a foreign key
- Delete data with a foreign key
- Set null
- Cascade
- Restrict
- No action
- Set default
- One-to-one
- Many-to-many
- One-to-many
- Custom primary key
- Bulk operations (save, update, delete)
- Migrations
Full Changelog: v0.2.0...v0.2.1
v0.2.0
Added
- One-to-many relationship between tables
Example
To define a foreign key, use other models as fields in the model.
from ormagic import DBModel
class User(DBModel):
name: str
class Post(DBModel):
title: str
content: str
user: User
User.create_table()
Post.create_table()
user = User(name="John")
user.save()
Post(title="Hello", content="World", user=user).save()
# You can also save child models with new parent object in one step, this will save the parent object first and then the child object
Post(title="Hello", content="World", user=User(name="Alice")).save()Features and Roadmap
- Define table schema using Pydantic models
- Basic CRUD operations
- Save data to the database
- Read data from the database
- Update data in the database
- Delete data from the database
- Relationships between tables
- One-to-many
- Create a tables with a foreign key
- Save data with a foreign key
- Read data with a foreign key
- Update data with a foreign key
- Delete data with a foreign key
- Set null
- Cascade
- Restrict
- No action
- Set default
- One-to-one
- Many-to-many
- One-to-many
- Custom primary key
- Bulk operations (save, update, delete)
- Migrations
Full Changelog: v0.1.0...v0.2.0
v0.1.0
Features and Roadmap
- Define table schema using Pydantic models
- Basic CRUD operations
- Save data to the database
- Read data from the database
- Update data in the database
- Delete data from the database
- Custom primary key
- Bulk operations (save, update, delete)
- Relationships between tables
- One-to-one
- One-to-many
- Many-to-many
- Migrations