Repositories are the bridge between your domain model and the database. In HexCore every repository starts as an abstract interface in the domain layer — a subclass ofDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Indroic/HexCore/llms.txt
Use this file to discover all available pages before exploring further.
IBaseRepository[T] — and is fulfilled by a concrete implementation in the infrastructure layer. This separation ensures your domain stays free of database concerns and remains easily testable. This page covers the IBaseRepository contract, the limit_offset_pagination flag, and a full end-to-end example.
IBaseRepository[T]
IBaseRepository lives in hexcore.domain.repositories. It is a generic, abstract base class that defines the minimum CRUD contract every repository must honour.
Constructor
The Unit of Work that owns this repository instance. Injected automatically when the UoW is initialised. The repository stores it as
self.uow for use in transaction-aware operations.Class attribute
When
True (the default), list_all() implementations should respect the limit and offset arguments and apply pagination at the database level. Set this to False if the underlying data source handles pagination differently or not at all.Abstract methods
Fetch a single entity by its UUID primary key. Raise a domain-specific
NotFoundException (or equivalent) if no record is found.Return a list of entities. Both parameters are optional.
| Parameter | Type | Default | Description |
|---|---|---|---|
limit | int | None | None | Maximum number of records to return. None means no limit. |
offset | int | 0 | Number of records to skip. |
Persist a new or modified entity. Returns the saved entity (which may have database-generated fields updated, such as an auto-increment ID or server-side timestamp).
Remove an entity from the store. Whether this performs a hard or soft delete depends on the concrete implementation.
Concrete method
Calls
get_by_id() and then checks entity.is_active. If the entity is inactive, raises InactiveEntityException. Use this method instead of get_by_id() when you need to enforce the soft-delete contract.Defining a domain interface
Create a subclass ofIBaseRepository in your domain layer. Keep it purely abstract — no database imports.
Implementing in infrastructure
The infrastructure layer provides the concrete class that connects the domain interface to the database. The example below shows a SQLAlchemy implementation stub that extendsIUserRepository.
Registering repositories for discovery
For HexCore’s Unit of Work to find and wire your repository, the module containing the concrete implementation must be listed inrepository_discovery_paths inside your config.py:
config.py