Skip to main content

Documentation 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.

A Query represents a request for information — it has no side effects and changes no state. In CQRS, read operations are modelled separately from commands so that read paths can be optimised, cached, or served from read replicas independently of the write path. HexCore’s Query base class is a frozen Pydantic model that is generic over TResult, letting the type system verify that the query handler returns exactly the type the caller expects.
from hexcore.domain.cqrs.queries import Query

Class definition

class Query(BaseModel, Generic[TResult]):
    model_config = ConfigDict(
        frozen=True,
        from_attributes=True,
    )

Generic type parameter

TResult
TypeVar
The return type produced by the handler that processes this query. Declare it when subclassing Query to propagate the expected return type all the way through the bus and handler interfaces.
Query itself has no default fields. Unlike Command, it deliberately omits auto-generated IDs and timestamps because read operations are stateless and do not require audit trail metadata.

Model configuration

OptionValueEffect
frozenTrueQuery objects are immutable and hashable after construction, preventing accidental mutation in middleware.
from_attributesTrueAllows constructing a query from attribute-bearing objects (ORM rows, dataclasses) via Query.model_validate(obj).

Type aliases

TResult = TypeVar("TResult")
TQuery = TypeVar("TQuery", bound=Query[Any])
TResult
TypeVar
Unconstrained type variable representing the result a query handler will return. Parameterise your Query subclass with this to propagate static type information through buses and handlers.
TQuery
TypeVar
A type variable bound to Query[Any]. Used in AbstractQueryHandler to constrain which query type a handler accepts.

Usage example

from uuid import UUID
from hexcore.domain.cqrs.queries import Query
from myapp.dto import ProductDTO

class GetProductByIdQuery(Query[ProductDTO]):
    product_id: UUID
Queries are never routed to background workers — they must return data synchronously. If you find yourself wanting an async query result, reconsider whether you need a read-model projection or a different architectural pattern (e.g., polling a cache updated by a domain event handler).

Build docs developers (and LLMs) love