httk.core.storage.stored_properties¶
Backend-neutral declarations for properties of durable entry backings.
An entry family may have several concrete durable representations. Each
backing declares its own served-property map with
StoredPropertyProjection; the declaration remains entirely in the
domain package while a storage implementation translates its query callbacks
to its native query language. Nothing here assumes SQL, OPTIMADE, or a
particular record family.
The query protocols deliberately describe expression construction, rather
than expression evaluation. A domain callback only receives a
QueryContext; the storage backend supplies its implementation and is
therefore free to use SQL, a document query, or an in-memory evaluator.
Attributes¶
Exact-class attribute holding a backing's property-projection mapping. |
|
Extract one served property value from one concrete backing record. |
|
Build one predicate from a context, protocol operator, and parsed literal. |
|
Select one sortable backing value from a query context. |
Exceptions¶
A query literal cannot represent the property value requested. |
Classes¶
One backend-neutral boolean predicate. |
|
A scalar or aggregate value participating in a query expression. |
|
A durable field selected from a |
|
A record or correlated child/reference scope. |
|
Factory and algebra used by domain-owned property query callbacks. |
|
One domain-owned projection of a served property for one backing. |
Functions¶
Return a validated property's projection map declared on |
Module Contents¶
- httk.core.storage.stored_properties.STORED_PROPERTY_PROJECTIONS_ATTRIBUTE: Final = '__httk_stored_properties__'¶
Exact-class attribute holding a backing’s property-projection mapping.
- exception httk.core.storage.stored_properties.QueryLiteralError[source]¶
Bases:
ValueErrorA query literal cannot represent the property value requested.
This is intentionally distinct from a query expression which simply matches no records. Protocol layers can translate it into their user-facing invalid-filter-value error without depending on a domain package’s parser exception.
- class httk.core.storage.stored_properties.QueryExpression[source]¶
Bases:
ProtocolOne backend-neutral boolean predicate.
Query callbacks compose predicates with the ordinary boolean operators; the backend decides how to retain SQL’s three-valued null semantics (or an equivalent semantics in another storage engine).
- class httk.core.storage.stored_properties.QueryValue[source]¶
Bases:
ProtocolA scalar or aggregate value participating in a query expression.
- class httk.core.storage.stored_properties.QueryField[source]¶
Bases:
QueryValue,ProtocolA durable field selected from a
QueryScope.
- class httk.core.storage.stored_properties.QueryScope[source]¶
Bases:
ProtocolA record or correlated child/reference scope.
scope(name)follows a durable reference or child relationship while retaining correlation to this scope. It intentionally does not say whether that relationship is one-to-one or a collection:existsand the aggregate methods onQueryContextgive both cases a single, portable vocabulary. Everyscopecall creates a distinct peer scope, even for the same relationship name, so a callback can compare correlated child rows without an accidental self-alias.- field(name)[source]¶
Return the durable scalar field named
namein this scope.- Parameters:
name (str) – The durable field name.
- Returns:
A query value representing that field.
- Return type:
- class httk.core.storage.stored_properties.QueryContext[source]¶
Bases:
QueryScope,ProtocolFactory and algebra used by domain-owned property query callbacks.
fieldandscopestart at the backing record.scopecan be called again on a child/reference scope, so callbacks can express correlated nested predicates without seeing storage tables or joins.exact_equalrequests equality in the property’s exact stored domain; it is the operation to use for fractions and other values for which a presentation float would be lossy.- constant(value)[source]¶
Return a query value for an already validated literal constant.
- Parameters:
value (object) – The validated literal to place in the query.
- Returns:
A query value for the literal.
- Return type:
- null()[source]¶
Return the explicit null query value.
- Returns:
A query value representing null.
- Return type:
- always_true()[source]¶
Return the predicate which matches every backing record.
- Returns:
A predicate that always matches.
- Return type:
- always_false()[source]¶
Return the predicate which matches no backing record.
- Returns:
A predicate that never matches.
- Return type:
- compare(left, operator, right)[source]¶
Compare values with a backend-supported comparison operator.
Domain callbacks normally use
equal(),exact_equal(), or explicit operator dispatch for a protocol’s filter grammar. The operator is deliberately a string so this contract does not own an external query language’s token enum.- Parameters:
left (QueryValue) – The left query value.
operator (str) – The backend-supported comparison operator.
right (QueryValue) – The right query value.
- Returns:
The comparison predicate.
- Return type:
- equal(left, right)[source]¶
Compare values using the backing’s ordinary stored semantics.
- Parameters:
left (QueryValue) – The left query value.
right (QueryValue) – The right query value.
- Returns:
The equality predicate.
- Return type:
- exact_equal(left, right)[source]¶
Compare values in their exact canonical stored representation.
- Parameters:
left (QueryValue) – The left query value.
right (QueryValue) – The right query value.
- Returns:
The exact equality predicate.
- Return type:
- is_null(value)[source]¶
Test a value for null; invert this predicate for a known-value test.
- Parameters:
value (QueryValue) – The query value to test.
- Returns:
The null-test predicate.
- Return type:
- exists(scope, predicate)[source]¶
Test whether a correlated scope contains a row satisfying
predicate.- Parameters:
scope (QueryScope) – The correlated scope to inspect.
predicate (QueryExpression) – The predicate required of a matching row.
- Returns:
The existence predicate.
- Return type:
- filtered(scope, predicate)[source]¶
Return the correlated subset of
scopesatisfyingpredicate.The returned scope is usable by aggregate operations. In particular, it lets a declaration compare a required multiplicity with the exact number of matching child values rather than reusing one
existswitness for repeated values.- Parameters:
scope (QueryScope) – The correlated scope to filter.
predicate (QueryExpression) – The predicate required of retained rows.
- Returns:
A correlated scope containing only matching rows.
- Return type:
- count(scope)[source]¶
Return the number of rows in a correlated child/reference scope.
- Parameters:
scope (QueryScope) – The correlated scope to count.
- Returns:
A query value containing the row count.
- Return type:
- distinct_count(scope, value)[source]¶
Return the count of distinct
valuevalues inscope.- Parameters:
scope (QueryScope) – The correlated scope to count.
value (QueryValue) – The value whose distinct occurrences are counted.
- Returns:
A query value containing the distinct count.
- Return type:
- scaled_exact_equal(left, left_factor, right, right_factor)[source]¶
Compare two exact values after cross multiplication.
This is the portable, exact form of a proportional comparison. It avoids requiring a backend to divide fractions or approximate a ratio through a presentation float: it asserts
left * left_factor == right * right_factorin the backing’s canonical exact domain.- Parameters:
left (QueryValue) – The first exact value.
left_factor (QueryValue) – The factor applied to the first value.
right (QueryValue) – The second exact value.
right_factor (QueryValue) – The factor applied to the second value.
- Returns:
The cross-multiplied equality predicate.
- Return type:
- and_(*predicates)[source]¶
Conjoin predicates; an empty conjunction is
always_true().- Parameters:
*predicates (QueryExpression) – The predicates to conjoin.
- Returns:
The conjunction predicate.
- Return type:
- or_(*predicates)[source]¶
Disjoin predicates; an empty disjunction is
always_false().- Parameters:
*predicates (QueryExpression) – The predicates to disjoin.
- Returns:
The disjunction predicate.
- Return type:
- not_(predicate)[source]¶
Negate a predicate without relying on a backend’s Python truthiness.
- Parameters:
predicate (QueryExpression) – The predicate to negate.
- Returns:
The negated predicate.
- Return type:
- when_known(known, predicate)[source]¶
Evaluate
predicateonly whenknownis true, else return unknown.This is the backend-neutral three-valued-logic form of
CASE WHEN known THEN predicate ELSE NULL END. It keeps incomplete nullable domain data unknown under both a predicate and its negation instead of silently treating the missing representation as a non-match.- Parameters:
known (QueryExpression) – The predicate establishing that the value is available.
predicate (QueryExpression) – The predicate evaluated only when
knownmatches.
- Returns:
The conditional three-valued predicate.
- Return type:
- type httk.core.storage.stored_properties.StoredPropertyResponse = Callable[[object], object]¶
Extract one served property value from one concrete backing record.
- type httk.core.storage.stored_properties.StoredPropertyQuery = Callable[[QueryContext, str, object], QueryExpression]¶
Build one predicate from a context, protocol operator, and parsed literal.
- type httk.core.storage.stored_properties.StoredPropertySort = Callable[[QueryContext], QueryValue]¶
Select one sortable backing value from a query context.
- class httk.core.storage.stored_properties.StoredPropertyProjection[source]¶
One domain-owned projection of a served property for one backing.
responseis called with a concrete backing record and returns its protocol-boundary value.queryreceives a backend-neutral context, the protocol comparison operator, and its parsed literal; it returns a predicate or raisesQueryLiteralErrorwhen the literal has no valid representation for this property.Nonemeans that a property is response-only for this backing.sortidentifies a direct sortable value and is intentionally separate from filtering because not every predicate has a meaningful total ordering.- Parameters:
response – The operation that extracts the served value from a backing record.
query – The optional operation that builds filtering predicates.
sort – The optional operation that selects a value for ordering.
- Raises:
TypeError – If a supplied projection operation cannot be invoked.
- response: StoredPropertyResponse¶
- query: StoredPropertyQuery | None = None¶
- sort: StoredPropertySort | None = None¶
- httk.core.storage.stored_properties.stored_property_projections(cls)[source]¶
Return a validated property’s projection map declared on
cls.The lookup deliberately uses
vars()rather thangetattr(). A representation-specific property mapping must be opted into by the exact backing class; subclasses never inherit a parent’s mapping by accident. A class without the declaration serves no stored properties.- Parameters:
cls (type[Any]) – The exact frozen dataclass backing class to inspect.
- Returns:
Its validated projection map, or an empty map when undeclared.
- Raises:
TypeError – If
clsis not a directly declared frozen dataclass or its map is invalid.ValueError – If a projection name is invalid.
- Return type: