Skip to content

Releases: SpaceShaman/ORMagic

v0.4.0

25 Jul 10:50

Choose a tag to compare

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_table method in the DBModel class to drop a table from the database.

Tests

  • Added a test case in test_save.py to ensure that the uniqueness constraint work properly.
  • Added a test case for the drop_table method in test_remove_table.py.

Documentation

  • Updated README.md to 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.yml to specify coverage for the ormagic package 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
  • 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

24 Jul 13:04

Choose a tag to compare

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

  • 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
  • Custom primary key
  • Bulk operations (save, update, delete)
  • Migrations

Full Changelog: v0.2.1...v0.3.0

v0.2.1

23 Jul 21:53

Choose a tag to compare

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_data method 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 DBModel class.

Tests

  • Added unit tests for the _create_instance_from_data and _prepare_fields_to_update methods, including tests for handling foreign key values.
  • Created a new test file test_prepare_values_to_insert.py to test the _prepare_values_to_insert method.
  • 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 None for 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
  • Custom primary key
  • Bulk operations (save, update, delete)
  • Migrations

Full Changelog: v0.2.0...v0.2.1

v0.2.0

23 Jul 19:50

Choose a tag to compare

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
  • Custom primary key
  • Bulk operations (save, update, delete)
  • Migrations

Full Changelog: v0.1.0...v0.2.0

v0.1.0

22 Jul 18:42

Choose a tag to compare

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