Skip to content

Releases: SpaceShaman/ORMagic

v0.15.0

26 Oct 08:48
Compare
Choose a tag to compare

This release introduces several new features, configuration options, and improvements to database connection handling, with a focus on consistency, clarity, and error handling.

New Features

  • Added possibility to configure the database URL via the ORMAGIC_DATABASE_URL environment variable.
  • Added possibility to configure the journal mode via the ORMAGIC_JOURNAL_MODE environment variable.

Refactoring

  • Refactor connection handling using the Factory Method design pattern alongside Protocol and ABC, resulting in cleaner and more modular code.
  • Use the Settings class for managing database configuration.

Bug Fixes

  • Prevent invalid database connections with unsupported databases by raising exceptions.

Full Changelog: v0.14.0...v0.15.0

v0.14.0

20 Oct 06:36
Compare
Choose a tag to compare

Atomic Transactions feature has been added. This allows grouping multiple operations together in an atomic way, ensuring all operations are applied successfully or none at all.

New Features

  • Introduced atomic transactions with a transaction context manager. This ensures that all operations within a transaction are either committed or rolled back if an error occurs.

Usage

from ormagic import DBModel, transaction

class User(DBModel):
    name: str
    age: int

with transaction():
    user1 = User(name="John", age=30)
    user1.save()

    user2 = User(name="Alice", age=25)
    user2.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
        • Cascade
        • Set null
        • Restrict
        • Set default
        • No action
    • One-to-one
    • Many-to-many
  • Unique constraints
  • Remove table
  • Read all data from the database
  • Filter data and retrieve multiple records
    • Equal
    • Not equal
    • Greater than
    • Greater than or equal
    • Less than
    • Less than or equal
    • Like (Pattern matching with % and _)
    • Not like (Pattern matching with % and _)
    • In (List of values)
    • Not in (List of values)
    • Between (Two values)
    • Not between (Two values)
    • Q objects to combine filters (AND, OR, NOT)
  • Protect against SQL injection
  • Order by
  • Limit and offset
  • Update table schema
    • Add new column
    • Rename column
    • Drop column
  • Custom primary key
  • Transactions
  • Functions
    • Aggregate functions
    • String functions
    • Date and time functions
    • Mathematical functions
    • Control flow functions
  • Migrations
  • Integration with other databases

Full Changelog: v0.13.2...v0.14.0

v0.13.2

13 Sep 15:11
Compare
Choose a tag to compare

Refactoring

  • Added cursor parameter to various methods in models.py to improve database operation efficiency.
  • Reordered cursor parameter to be the first argument in functions for consistency and readability.
  • Refactored table management functions in models.py to use context-managed cursors for improved resource handling.
  • Updated DBModel methods to use a shared cursor for database operations.

Full Changelog: v0.13.1...v0.13.2

v0.13.1

12 Sep 14:42
Compare
Choose a tag to compare

This version focuses on improving the codebase's maintainability by refactoring database operations to use context managers.

Refactoring

  • Database Operations:
    • Updated models.py, sql_utils.py, and table_manager.py to use context managers for more efficient cursor management.
    • Improved code clarity and reduced the risk of resource leaks.

Full Changelog: v0.13.0...v0.13.1

v0.13.0

19 Aug 21:33
Compare
Choose a tag to compare

This update introduces a major feature—support for custom primary keys in models, enhancing flexibility in database schema design. Alongside this, several refinements and documentation improvements have been made to ensure better maintainability and user guidance.


Added

  • Custom Primary Keys:

    • Implemented support for custom primary key fields in models, allowing more flexible database schema definitions.
    • Updated documentation to include examples and guidelines for using custom primary keys.
  • Documentation Updates:

    • Added a new section on custom primary keys to the documentation.
    • Updated the README to reflect the completion of the custom primary key feature.

Example

from ormagic import DBModel, DBField

class User(DBModel):
    custom_id: int = DBField(primary_key=True)
    name: str

User.create_table()

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
  • Read all data from the database
  • Filter data and retrieve multiple records
    • Equal
    • Not equal
    • Greater than
    • Greater than or equal
    • Less than
    • Less than or equal
    • Like (Pattern matching with % and _)
    • Not like (Pattern matching with % and _)
    • In (List of values)
    • Not in (List of values)
    • Between (Two values)
    • Not between (Two values)
    • Q objects to combine filters (AND, OR, NOT)
  • Protect against SQL injection
  • Order by
  • Limit and offset
  • Update table schema
    • Add new column
    • Rename column
    • Drop column
  • Custom primary key
  • Functions
    • Aggregate functions
    • String functions
    • Date and time functions
    • Mathematical functions
    • Control flow functions
  • Bulk operations (save, update, delete)
  • Migrations
  • Integration with other databases

Full Changelog: v0.12.1...v0.13.0

v0.12.1

16 Aug 12:51
Compare
Choose a tag to compare

This release introduces a significant improvement to the project's documentation by migrating from the basic README-based documentation to a more robust and visually appealing setup using Material for MkDocs. This change enhances the overall user experience by providing a structured, easy-to-navigate, and professionally styled documentation site.


Added

  • Material for MkDocs Documentation:
    • Replaced the old README-based documentation with a new site built using Material for MkDocs.
    • Added a clear navigation structure to help users easily find information and examples.
    • Included detailed documentation sections covering installation, usage, and complex features like filtering with Q objects.
    • Set up GitHub Actions for automatic deployment of the documentation site.

Refactoring

  • Documentation Overhaul:
    • Removed most of the old documentation from the README and streamlined it to point to the new, comprehensive documentation site.
    • Enhanced formatting, readability, and structure across all documentation files using markdown extensions specific to MkDocs.

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
  • Read all data from the database
  • Filter data and retrieve multiple records
    • Equal
    • Not equal
    • Greater than
    • Greater than or equal
    • Less than
    • Less than or equal
    • Like (Pattern matching with % and _)
    • Not like (Pattern matching with % and _)
    • In (List of values)
    • Not in (List of values)
    • Between (Two values)
    • Not between (Two values)
    • Q objects to combine filters (AND, OR, NOT)
  • Protect against SQL injection
  • Order by
  • Limit and offset
  • Update table schema
    • Add new column
    • Rename column
    • Drop column
  • Custom primary key
  • Functions
    • Aggregate functions
    • String functions
    • Date and time functions
    • Mathematical functions
    • Control flow functions
  • Bulk operations (save, update, delete)
  • Migrations

Full Changelog: v0.12.0...v0.12.1

v0.12.0

15 Aug 14:22
Compare
Choose a tag to compare

This release introduces significant improvements in data filtering capabilities within the database. The new Q class allows for the creation of complex query filters using logical operators like AND, OR, and NOT. Additionally, refactoring has enhanced code readability and streamlined the handling of conditions in SQL queries.

Added

  • Support for Advanced Filters with the Q Class:
    • Introduced the Q class, enabling the creation of complex queries by combining various conditions using AND, OR, and NOT operators.
    • Capability to construct intricate queries, such as filtering data with multiple Q objects using logical AND/OR.

Refactoring

  • Improved Condition Handling in Queries:
    • Refactored the prepare_where_conditions method to accept positional arguments.
    • Simplified the _fetch_raw_data method by leveraging the refactored prepare_where_conditions function.
    • Refactored the Q class and related methods to enhance readability and improve SQL condition management.

Example

    q1 = Q(name="Alice")
    q2 = Q(age__lt=25)
    q3 = Q(weight__gte=70)
    q4 = Q(name="Bob")
    q5 = Q(age__gt=30)
    q6 = Q(weight__lte=80)
    q = Q(q1 & q2 | q3) | Q(q4 & q5 | q6)
    User.filter(q)

This is equivalent to the following SQL WHERE clause:

WHERE (name = 'Alice' AND age < 25 OR weight >= 70) OR (name = 'Bob' AND age > 30 OR weight <= 80)

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
  • Read all data from the database
  • Filter data and retrieve multiple records
    • Equal
    • Not equal
    • Greater than
    • Greater than or equal
    • Less than
    • Less than or equal
    • Like (Pattern matching with % and _)
    • Not like (Pattern matching with % and _)
    • In (List of values)
    • Not in (List of values)
    • Between (Two values)
    • Not between (Two values)
    • Q objects to combine filters (AND, OR, NOT)
  • Protect against SQL injection
  • Order by
  • Limit and offset
  • Update table schema
    • Add new column
    • Rename column
    • Drop column
  • Custom primary key
  • Functions
    • Aggregate functions
    • String functions
    • Date and time functions
    • Mathematical functions
    • Control flow functions
  • Bulk operations (save, update, delete)
  • Migrations

Full Changelog: v0.11.0...v0.12.0

v0.11.0

14 Aug 16:40
Compare
Choose a tag to compare

New Feature

  • Added functionality to drop columns from existing tables, providing more flexibility in managing database schemas.

This release focuses on enhancing database schema management by allowing the removal of columns from existing tables, further improving the flexibility and control over database structures.

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
  • Read all data from the database
  • Filter data and retrieve multiple records
    • Equal
    • Not equal
    • Greater than
    • Greater than or equal
    • Less than
    • Less than or equal
    • Like (Pattern matching with % and _)
    • Not like (Pattern matching with % and _)
    • In (List of values)
    • Not in (List of values)
    • Between (Two values)
    • Not between (Two values)
  • Protect against SQL injection
  • Order by
  • Limit and offset
  • Update table schema
    • Add new column
    • Rename column
    • Drop column
  • Custom primary key
  • Bulk operations (save, update, delete)
  • Migrations

Full Changelog: v0.10.1...v0.11.0

v0.10.1

14 Aug 15:58
Compare
Choose a tag to compare

Refactoring & Code Reorganization

  • Significant refactoring to improve code modularity, readability, and maintainability. The logic related to saving, updating, and managing database tables has been reorganized into dedicated modules (data_saver.py and table_manager.py), allowing for better separation of concerns.
  • Renamed methods and variables for clarity and consistency across the codebase.

New Features

  • Introduced support for column renaming and adding columns with constraints in the update_table method, enhancing the flexibility of schema updates.

SQLite Enhancements

  • Enabled Write-Ahead Logging (WAL) mode in SQLite for improved performance and concurrency.

Testing

  • Expanded tests to cover the new schema update features, ensuring reliability and robustness.

This update focuses on enhancing the internal structure of the code, making it more modular and easier to maintain, while also adding critical new functionality for database schema management.

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
  • Read all data from the database
  • Filter data and retrieve multiple records
    • Equal
    • Not equal
    • Greater than
    • Greater than or equal
    • Less than
    • Less than or equal
    • Like (Pattern matching with % and _)
    • Not like (Pattern matching with % and _)
    • In (List of values)
    • Not in (List of values)
    • Between (Two values)
    • Not between (Two values)
  • Protect against SQL injection
  • Order by
  • Limit and offset
  • Update table schema
    • Add new column
    • Rename column
    • Drop column
  • Custom primary key
  • Bulk operations (save, update, delete)
  • Migrations

Full Changelog: v0.10.0...v0.10.1

v0.10.0

04 Aug 13:40
Compare
Choose a tag to compare

The latest version focuses on query enhancements and code readability improvements. Here are the key changes:

New Features

  • Added support for limit and offset parameters in DBModel queries to enable pagination.

Refactoring

  • Renamed variables in the _fetch_raw_data method for better clarity.
  • Refactored the unique field check into a new _is_unique_field method for improved readability and reusability.

Tests

  • Added tests in test_pagination.py for limit and offset functionality.
  • Updated tests in test_get.py to ensure accurate validation of datetime fields.
  • Removed outdated and redundant test files.

Documentation

  • Updated README.md to include documentation for limit and offset parameters.
  • Marked limit and offset as completed in the feature list.

In summary, this update introduces pagination support, improves code readability, and ensures comprehensive testing and documentation for the new features.

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
  • Read all data from the database
  • Filter data and retrieve multiple records
    • Equal
    • Not equal
    • Greater than
    • Greater than or equal
    • Less than
    • Less than or equal
    • Like (Pattern matching with % and _)
    • Not like (Pattern matching with % and _)
    • In (List of values)
    • Not in (List of values)
    • Between (Two values)
    • Not between (Two values)
  • Protect against SQL injection
  • Order by
  • Limit and offset
  • Update table schema
  • Custom primary key
  • Bulk operations (save, update, delete)
  • Migrations

Full Changelog: v0.9.0...v0.10.0