Fake repo examplesΒΆ
This project contains a documented example in docs/examples-repo/index.md.
Recommended reading order:
Product commands and models.
Use cases with
RuleandCompute.Custom repository contract and SQLAlchemy implementation.
Interface declaration and route wiring.
Integration tests that validate end-to-end behavior using these examples.
These examples are the reference implementation for DSL usage and expected behavior.
Useful files:
tests/integration/fake_repo/product/repository_contract.pytests/integration/fake_repo/product/repository.pytests/integration/fake_repo/src/app/product/use_cases.pytests/integration/core/use_case/test_use_case_crud_integration.pytests/integration/core/use_case/test_custom_repository_integration.py
Custom repository pattern:
Declare the custom contract as
RepoFor[Model]plus only the extra methods.Import
repository_forfromloom.core.repository, not from the SQLAlchemy package.Register the SQLAlchemy implementation with
@repository_for(Model)and make the repository class inherit the capabilityProtocoldirectly.Keep CRUD-only use cases on
self.main_repo; they automatically receive the custom implementation.Reserve constructor-injected repository contracts for advanced cases where a use case or job needs a secondary repository dependency; the primary public example should stay on
main_repo.repository_for(...)also works for non-persistible logical types:use
LoomStructfor neutral internal structsuse
Responsefor API-facing structs that should serialize incamelCase
The SQLAlchemy bootstrap module now registers
DefaultRepositoryBuilderwithSQLAlchemyDefaultRepositoryBuilderas the current fallback forBaseModel.That fallback keeps
SessionManagerinside the SQLAlchemy adapter, so SQLAlchemy construction details do not leak into the core repository contract.To replace the project-wide backend, register another
DefaultRepositoryBuilderimplementation in the container;UseCase[Model, Result]will continue to resolveself.main_repothrough that new base repository.Explicit
repository_for(...)bindings still take precedence for both persistible and non-persistible types.When a custom repository needs more constructor dependencies than the default class path supports, use
repository_for(..., builder=...)and resolve those dependencies fromRepositoryBuildContext.container.