Repository navigation
release: v0.1.0-beta.8 - #94
Merged
Merged
Conversation
Refactor WriteRepositoryMixin.create_multi to leverage SQLAlchemy 2.0 insert().values().returning() execution. - Eliminate N+1 SELECT queries caused by the sequential refresh() loop. - Execute bulk inserts in a single atomic database statement. - Retrieve and return created model instances with resolved IDs directly.
Refactor WriteRepositoryMixin.update_multi to leverage SQLAlchemy 2.0 bulk update execution with the eturning() clause. - Eliminate initial SELECT query (get_by_ids) prior to updating records. - Remove Python-side in-memory setattr loops and subsequent refresh queries. - Execute batch updates with parameter lists via session.scalars().
Refactor WriteRepositoryMixin.delete_multi to leverage SQLAlchemy 2.0 bulk deletion with the eturning() clause. - Eliminate initial SELECT query (get_by_ids) and in-memory record loading. - Replace sequential per-record deletion with a single atomic DELETE statement. - Retrieve and return deleted model instances directly from session.scalars().
Refactor WriteRepositoryMixin.update_multi to execute bulk updates directly using SQLAlchemy 2.0 DBAPI executemany batching without pre-fetching. - Replace initial SELECT query and in-memory setattr loops with session.execute(update, payloads). - Synchronize and return updated instances using a single batch get_by_ids query. - Update repository unit tests to validate homogeneous bulk update semantics.
Introduce lifecycle isolation and automatic dependency injection for asynchronous background routines and tasks. - Implement �ackground_scope async context manager to manage independent IoC scopes, AsyncSession instances, and ZContext stores. - Implement @background_task decorator with signature inspection and automatic container dependency resolution.
Implement lifecycle isolation and automatic dependency injection for asynchronous and synchronous background operations. - Introduce �ackground_scope async context manager to manage independent IoC scopes, AsyncSession instances, and ZContext stores. - Implement @background_task decorator supporting both coroutines and sync functions (via anyio.to_thread.run_sync). - Add signature inspection for auto-wiring dependencies while preserving default arguments and explicit parameter overrides. - Add comprehensive test suite covering lifecycle isolation, context inheritance, error cleanup, and concurrency in test_di.py.
Add required import spacing in the dependency injection module.
Expose �ackground_scope and �ackground_task through the kernel package for convenient public access.
Extend the search engine with additional filtering capabilities. - Add contains, startwith, and endwith operators for string and collection fields. - Add �etween operator with value validation and type coercion. - Escape LIKE wildcards for string-based pattern matching.
Allow models to define a custom maximum relation inclusion depth. * Add __max_search_depth__ model configuration with a default depth of 3. * Use the configured depth when validating include relation paths. * Update search tests to reflect the configurable depth behavior.
Standardize string matching operators and expand search engine test coverage. * Rename startwith and endwith to startswith and endswith. * Add comprehensive tests for string matching and �etween operators. * Add validation tests for invalid �etween values. * Add coverage for configurable model filter depth limits.
Introduce a reusable soft-delete mixin for SQLAlchemy models. * Add SoftDeleteMixin with deleted_at tracking and deletion state checks. * Provide soft_delete() and estore() lifecycle methods. * Add scope_query() for filtering out soft-deleted records. * Export SoftDeleteMixin through the public zcore and zcore.db APIs.
Automatically apply soft-delete scopes to repository existence checks. * Update exist() to exclude soft-deleted records through scope_query(). * Add comprehensive soft-delete repository integration tests. * Cover filtering, counting, existence checks, ID lookups, search, and restore lifecycle.
Align the test suite with modern Python typing and formatting conventions. * Replace legacy Type and Optional annotations with built-in generics. * Reorganize imports and apply consistent formatting across tests. * Simplify context managers, exception handling, and unused variable patterns. * Improve test annotations with ClassVar and collections.abc types.
- Add interactive CLI dashboard with Questionary and Rich UI. - Support SQLite, PostgreSQL, and MySQL project initialization. - Add optional virtualenv setup with pip or uv. - Add configurable domain layer scaffolding with template/blank modes. - Add project discovery and project-aware command execution. - Improve env generation, secret generation, and server runner UX. - Add CLI tests for database drivers, project detection, scaffolding, and commands.
- update project ownership and maintainer metadata - add Python 3.13 support - add PostgreSQL and MySQL dependency groups - expand development dependencies - update Hatch, Ruff, and pytest documentation - refresh test architecture and contribution guidelines - update security documentation references - add project contact and copyright information
- update CLI feature descriptions and project scaffolding examples - document interactive TUI and context-aware project detection - add database driver and virtual environment setup details - document granular domain layer scaffolding modes - add interactive and non-interactive CLI command reference - update endpoint count and project attribution
## Description Refactored bulk write operations (`create_multi`, `update_multi`, and `delete_multi`) in `WriteRepositoryMixin` to leverage native SQLAlchemy 2.0 batch execution patterns and `RETURNING` clauses, significantly reducing database round-trips and ORM hydration overhead. ### Summary of Changes: - **`create_multi`**: Replaced sequential `db.add_all()` and per-record `refresh()` loops with an atomic `insert().values().returning()` execution to eliminate N+1 select queries. - **`update_multi`**: Replaced pre-fetching (`get_by_ids`) and in-memory Python `setattr` loops with a direct DBAPI `executemany` update batch (`db.execute(update(self.model), payloads)`), synchronizing records via a single batch query. - **`delete_multi`**: Replaced entity pre-fetching and sequential `db.delete()` calls with a single atomic `delete().where().returning()` statement. - **Unit Tests**: Updated repository tests in `tests/test_repository.py` to align with the optimized bulk update semantics. Fixes # (issue number) ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [x] Refactoring (architectural or code cleanup with no functional changes) - [ ] Documentation update ## How Has This Been Tested? - [x] Unit/Integration tests (`hatch test`) - Updated and ran `tests/test_repository.py` (`test_repo_update_multi`) to verify atomic batch execution, returning results, and database persistence. - [x] Static type check passing (`mypy src/`) ## Checklist: - [x] My code follows the style guidelines and architectural rules of this project - [x] I have performed a self-review of my own code - [x] My changes pass strict static type analysis (`mypy src/` generates no warnings) - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation in `zcore-docs` if applicable - [x] My changes generate no new runtime warnings - [x] I have added tests that prove my fix is effective or that my feature works
…ing (#87) ## Description Introduced lifecycle isolation, dedicated database session management, and automatic dependency injection for asynchronous background routines and synchronous tasks scheduled outside the primary HTTP request lifecycle. ### Summary of Changes: - **`background_scope`**: Implemented an async context manager in `zcore.kernel.di` that establishes an isolated IoC scope (`_current_scope_id`), provisions an independent `AsyncSession`, and manages context variable cloning (`_request_context_store`) with guaranteed resource disposal upon exit. - **`@background_task` Decorator**: Added a decorator with parameter signature inspection that auto-resolves type-annotated dependencies directly from the global IoC container while preserving explicit argument overrides. - **Sync/Async Support**: Enabled execution support for both coroutines and synchronous functions (offloaded to thread pools via `anyio.to_thread.run_sync`). - **Package Exports**: Exposed `background_scope` and `background_task` through `zcore.kernel` for direct public access. - **Test Suite**: Added comprehensive test cases in `tests/test_di.py` verifying context inheritance, scope isolation under concurrency, error cleanup guarantees, and dependency resolution. Fixes # (issue number) ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Refactoring (architectural or code cleanup with no functional changes) - [ ] Documentation update ## How Has This Been Tested? - [x] Unit/Integration tests (`hatch test`) - Added and executed 8 test cases in `tests/test_di.py` (`test_background_scope_*` and `test_background_task_*`) validating isolation, context inheritance, error handling, sync/async task execution, and concurrent execution safety. - [x] Static type check passing (`mypy src/`) ## Checklist: - [x] My code follows the style guidelines and architectural rules of this project - [x] I have performed a self-review of my own code - [x] My changes pass strict static type analysis (`mypy src/` generates no warnings) - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation in `zcore-docs` if applicable - [x] My changes generate no new runtime warnings - [x] I have added tests that prove my fix is effective or that my feature works
…th (#88) ## Description Enhanced the database search engine with advanced string and range filtering operators (`contains`, `startswith`, `endswith`, `between`) and introduced configurable maximum relation inclusion depth per entity model. ### Summary of Changes: - **New Filter Operators**: - `startswith` & `endswith`: Added string pattern matching with automatic LIKE wildcard escaping (`%` and `_`). - `contains`: Added case-insensitive substring matching for string fields (with LIKE wildcard escaping) and fallback to collection containment for non-string types. - `between`: Added range filtering with list length validation (exactly 2 elements) and column type coercion for numbers and datetimes. - **Configurable Relation Depth**: - Added support for `__max_search_depth__` attribute on SQLAlchemy models (defaulting to 3). - Updated `SearchEngine._validate_request` to dynamically enforce relation inclusion path depth based on the target model's configured depth limit. - **Test Suite Expansion**: - Added comprehensive unit tests in `tests/test_search.py` covering all new operators (`startswith`, `endswith`, `contains`, `between`), range input validation errors, and custom entity depth limits. Fixes # (issue number) ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Refactoring (architectural or code cleanup with no functional changes) - [ ] Documentation update ## How Has This Been Tested? - [x] Unit/Integration tests (`hatch test`) - Added and verified tests in `tests/test_search.py` for new string matching operators, numeric/datetime `between` operations, invalid range payload validation, and custom `__max_search_depth__` enforcement. - [x] Static type check passing (`mypy src/`) ## Checklist: - [x] My code follows the style guidelines and architectural rules of this project - [x] I have performed a self-review of my own code - [x] My changes pass strict static type analysis (`mypy src/` generates no warnings) - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation in `zcore-docs` if applicable - [x] My changes generate no new runtime warnings - [x] I have added tests that prove my fix is effective or that my feature works
) ## Description Introduced a reusable `SoftDeleteMixin` for SQLAlchemy models to support non-destructive record deletion and automatic filtering across repository queries. ### Summary of Changes: - **`SoftDeleteMixin` Implementation**: - Created `SoftDeleteMixin` in `src/zcore/db/soft_delete.py` with an indexed, timezone-aware `deleted_at` timestamp. - Added `is_deleted` property and `soft_delete()` / `restore()` lifecycle methods. - Provided `scope_query()` classmethod to automatically exclude deleted records (`deleted_at.is_(None)`). - **Repository Integration**: - Updated `BaseRepository.exist()` in `src/zcore/db/repository.py` to inspect the model for `scope_query` and filter out soft-deleted records from existence checks. - **Public API Exports**: - Exported `SoftDeleteMixin` across `zcore.db` and top-level lazy exports in `zcore.__init__.py`. - **Test Suite**: - Added unit and integration tests in `tests/test_soft_delete.py` covering state transitions, repository lookups (`get`, `get_list`, `get_by_ids`), existence and counting (`exist`, `count`), search integration, and the full soft-delete/restore lifecycle. Fixes # (issue number) ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Refactoring (architectural or code cleanup with no functional changes) - [ ] Documentation update ## How Has This Been Tested? - [x] Unit/Integration tests (`hatch test`) - Added and executed test cases in `tests/test_soft_delete.py` validating model state changes, query filtering, count/existence accuracy, search integration, and record restoration. - [x] Static type check passing (`mypy src/`) ## Checklist: - [x] My code follows the style guidelines and architectural rules of this project - [x] I have performed a self-review of my own code - [x] My changes pass strict static type analysis (`mypy src/` generates no warnings) - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation in `zcore-docs` if applicable - [x] My changes generate no new runtime warnings - [x] I have added tests that prove my fix is effective or that my feature works
## Description Refactored and modernized the entire test suite to align with PEP 585/PEP 604 typing conventions, cleaner context management patterns, and consistent code formatting across test modules. ### Summary of Changes: - **Type Annotations & Modern Generics**: - Replaced legacy `typing.Type`, `typing.Optional`, and `typing.AsyncGenerator`/`typing.Generator` with built-in generics (`type[...]`, `T | None`, `collections.abc.AsyncGenerator`, `collections.abc.Generator`). - Added explicit `ClassVar` annotations on test-class attributes in `test_testing_subsystem.py` and `test_web.py`. - **Code Cleanliness & Context Management**: - Simplified multi-context blocks and nested `async with` / `with` statements. - Replaced boilerplate `try...except Pass` blocks with `contextlib.suppress()` where appropriate. - Cleaned up unused variable names (e.g., prefixing unused iteration variables with `_`). - **Import & Style Cleanups**: - Deduplicated and reorganized imports across all test files. Fixes # (issue number) ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [x] Refactoring (architectural or code cleanup with no functional changes) - [ ] Documentation update ## How Has This Been Tested? - [x] Unit/Integration tests (`hatch test`) - Ran the full test suite across all modules (`test_cache`, `test_cli`, `test_config`, `test_context`, `test_db_lifecycle`, `test_di`, `test_exceptions`, `test_pagination`, `test_repository`, `test_search`, `test_security`, `test_service`, `test_storage`, `test_streams`, `test_testing_subsystem`, `test_web`) to ensure 100% pass rate without behavioral regressions. - [x] Static type check passing (`mypy src/`) ## Checklist: - [x] My code follows the style guidelines and architectural rules of this project - [x] I have performed a self-review of my own code - [x] My changes pass strict static type analysis (`mypy src/` generates no warnings) - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation in `zcore-docs` if applicable - [x] My changes generate no new runtime warnings - [x] I have added tests that prove my fix is effective or that my feature works
#91) ## Description Revamped the ZCore CLI tool (`zc`) with interactive terminal dashboards, dynamic database driver configuration, automated virtual environment setups, and fine-grained domain layer scaffolding. ### Summary of Changes: - **Interactive UI & Terminal Dashboard**: - Integrated `questionary` and `rich` to provide an interactive CLI dashboard with styled banners, step workflows, and status spinners (`src/zcore/cli/ui.py`). - Added workspace awareness with automatic project discovery (`find_zcore_projects`, `is_zcore_project`) to run commands or scaffold modules across multiple local projects. - **Enhanced Project Initialization (`zc init`)**: - Added multi-database driver support (`sqlite` via `aiosqlite`, `postgres` via `asyncpg`, `mysql` via `aiomysql`) with driver-specific `.env` generation and dependency injection into `requirements.txt`. - Added automated `.venv` initialization and dependency installation with optional `uv` or `pip` package manager selection. - **Configurable Domain App Scaffolding (`zc startapp`)**: - Introduced granular scaffolding modes (`Full Boilerplate`, `Clean / Blank`, `Custom / Mixed`) allowing selective generation of models, schemas, repositories, services, routers, plugins, and tests. - **CLI Commands & Server Runner UX**: - Updated `run` to resolve `.env` host/port parameters and execute Uvicorn directly with proper `PYTHONPATH` targeting. - Added `gen_secret` with formatted output panels and improved `gen_env` settings discovery. - **Test Suite**: - Expanded `tests/test_cli.py` to cover non-interactive flags (`--db`, `-y`, `--no-template`, `--no-test`), project detection helpers, driver dependency validation, and dashboard cancel handlers. Fixes # (issue number) ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Refactoring (architectural or code cleanup with no functional changes) - [ ] Documentation update ## How Has This Been Tested? - [x] Unit/Integration tests (`hatch test`) - Ran CLI test suite (`tests/test_cli.py`) validating non-interactive project creation across SQLite/Postgres/MySQL drivers, modular app scaffolding variations, secret/env generators, and project discovery utilities. - [x] Static type check passing (`mypy src/`) ## Checklist: - [x] My code follows the style guidelines and architectural rules of this project - [x] I have performed a self-review of my own code - [x] My changes pass strict static type analysis (`mypy src/` generates no warnings) - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation in `zcore-docs` if applicable - [x] My changes generate no new runtime warnings - [x] I have added tests that prove my fix is effective or that my feature works
…entation (#92) ## Description Modernized project packaging metadata, expanded database and development dependency groups in `pyproject.toml`, added Python 3.13 classifier support, and comprehensively refreshed contribution, security, and CLI documentation across the repository. ### Summary of Changes: - **Packaging & Dependency Groups (`pyproject.toml`)**: - Added maintainer metadata and added Python 3.13 to project classifiers. - Added dedicated optional dependency groups for `postgres` (`asyncpg`), `mysql` (`aiomysql`), and `dev` (`pytest`, `mypy`, `ruff`, `httpx`). - Updated the `all` dependency group to bundle `asyncpg` and `aiomysql`. - **Documentation Overhauls (`README.md`)**: - Updated CLI guide to document the interactive TUI wizard, automated `uv` / `.venv` environment setup, and granular domain scaffolding modes. - Added full interactive and non-interactive command table references. - Updated quickstart instructions, endpoint counts, and author/maintainer attribution. - **Contribution Guidelines (`CONTRIBUTING.md`, `CODE_OF_CONDUCT.md`)**: - Documented modular flat test structure under `tests/`. - Updated test runner guidelines to use `hatch test` and `@pytest.mark.anyio`. - Updated code formatting instructions to use `ruff check .` and `ruff format --check .`. - Added maintainer contact information in `CODE_OF_CONDUCT.md`. - **Security & Licensing References (`SECURITY.md`, `LICENSE`)**: - Updated file path references to match current module layout (`zcore/security/security.py`, `zcore/web/projection.py`, `zcore/storage/local.py`). - Added copyright notice in `LICENSE`. Fixes # (issue number) ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Refactoring (architectural or code cleanup with no functional changes) - [x] Documentation update ## How Has This Been Tested? - [x] Unit/Integration tests (`hatch test`) - [x] Static type check passing (`mypy src/`) ## Checklist: - [x] My code follows the style guidelines and architectural rules of this project - [x] I have performed a self-review of my own code - [x] My changes pass strict static type analysis (`mypy src/` generates no warnings) - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have updated the documentation in `zcore-docs` if applicable - [x] My changes generate no new runtime warnings - [x] I have added tests that prove my fix is effective or that my feature works
…le-generic API signature
…le-generic API signature (#93) ## Description Aligned CLI code generation templates for repositories and services with `zcore`'s single-generic class definitions and introduced automated validation tests to verify that scaffolded domain files compile successfully. ### Summary of Changes: - **CLI Templates (`src/zcore/cli/templates.py`)**: - Updated repository scaffolding template (`REPOSITORY_TEMPLATE`) to inherit from `BaseRepository[{ModelName}]` instead of the legacy three-type parameter signature (`BaseRepository[{ModelName}, {ModelName}Create, {ModelName}Update]`). - Updated service scaffolding template (`SERVICE_TEMPLATE`) to inherit from `BaseService[{ModelName}]` instead of `BaseService[{ModelName}, {ModelName}Create, {ModelName}Update]`. - **CLI Test Suite (`tests/test_cli.py`)**: - Added `test_scaffolded_templates_are_valid_python` test case to execute `zc init` and `zc startapp` in an isolated environment and ensure all generated Python template files compile cleanly via `compile(..., "exec")`. Fixes # (issue number) ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Refactoring (architectural or code cleanup with no functional changes) - [ ] Documentation update ## How Has This Been Tested? - [x] Unit/Integration tests (`hatch test`) - [x] Static type check passing (`mypy src/`) ## Checklist: - [x] My code follows the style guidelines and architectural rules of this project - [x] I have performed a self-review of my own code - [x] My changes pass strict static type analysis (`mypy src/` generates no warnings) - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have updated the documentation in `zcore-docs` if applicable - [x] My changes generate no new runtime warnings - [x] I have added tests that prove my fix is effective or that my feature works
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Release
v0.1.0-beta.8aggregating database write/search performance optimizations, background execution isolation, soft delete lifecycle capabilities, complete interactive CLI revitalization, test suite modernization, and updated packaging/documentation metadata.Summary of Changes:
create_multi,update_multi,delete_multi) inWriteRepositoryMixinusing native SQLAlchemy 2.0RETURNINGclauses and direct DBAPIexecutemanyexecution, eliminating N+1 select queries and ORM hydration overhead.background_scopeasync context manager for isolated IoC containers, dedicatedAsyncSessioninstances, and context cloning.@background_taskdecorator supporting sync (thread pool offloading) and async functions with automatic parameter auto-wiring.zcore.kernel.startswith,endswith,contains(case-insensitive substring & collection matching), andbetween(range filtering with type coercion).__max_search_depth__on SQLAlchemy models to dynamically enforce inclusion relation path limits.SoftDeleteMixinprovidingdeleted_attimestamp tracking,is_deletedproperty,soft_delete()andrestore()methods.scope_query()checks acrossBaseRepository.exist()and query execution.zcCLI with an interactive Questionary/Rich dashboard, workspace detection, and automated.venvcreation viauv/pip.SQLite,PostgreSQL,MySQL).Full Boilerplate,Clean / Blank,Custom).BaseRepository[Model],BaseService[Model]).collections.abctypes.postgres,mysql, anddev.README.md,CONTRIBUTING.md,SECURITY.md, andCODE_OF_CONDUCT.md.Type of change
How Has This Been Tested?
hatch test)test_db_lifecycle,test_repository,test_search,test_soft_delete,test_di,test_cli,test_web,test_security, etc.).mypy src/)Checklist:
mypy src/generates no warnings)zcore-docsif applicable