Skip to content

QuerySpec

Immutable query specification object used by repositories.

Encapsulates:

  • SQL statement
  • operation type
  • parameters
  • fetch strategy

Design Goals

  • decouple query definition from execution
  • enforce query invariants
  • standardize repository behavior

backend.database.infrastructure.query_spec.QuerySpec dataclass

Immutable specification of a database query.

Encapsulates the sql string, its operation type, bound parameters, and expected fetch behaviour. Designed to decouple query definition from execution logic inside repositories.

Attributes:

Name Type Description
sql str

parameterized SQL statement

operation OperationType

type of database operations (read or write)

params Sequence[Any]

positional parameters bound to the SQL statement.

fetch Optional[FetchType]

Fetch strategy, defined only for read operations (one or all)

Invariants
  • READ operations must define fetch type
  • WRITE operations cannot have a fetch type