httk.store.query.protocols¶
Typed protocols for the store/searcher query contract.
These protocols define the backend-agnostic query interface shared by httk
data stores: the database layer in httk-store implements them over SQL, and
serving modules (such as httk-serve, whose in-memory store also conforms)
program against them. They mirror the query interface of the httk v1 database
layer (httk.db FilteredCollection searchers), so lightweight fakes can
stand in for a real store in tests.
Attributes¶
The backend field name used for the served entry identifier. |
Exceptions¶
Report that a valid query operation is outside a store's supported profile. |
|
Report that a store cannot provide an exact query count. |
|
Report that a result-set |
|
Report that a result-set |
|
Report that a continuation cursor is malformed, expired, or belongs to another result plan. |
Classes¶
Order a continuation page by one named scalar result projection. |
|
Carry an opaque URL-safe continuation value. |
|
Represent an immutable continuation-page result. |
|
Expose optional continuation-page capability on a frozen result set. |
|
Represent one named result row by position, name, or attribute. |
|
Require named access to one result row. |
|
Require the common operations of a materialized result set. |
|
Require composable backend search expressions. |
|
Expose a queryable field of a search variable. |
|
Bind a query variable to a target type whose attributes yield fields. |
|
Build one query; consume it through |
|
A searcher plus its private, backend-internal raw query surface. |
|
Require a store that can create a query searcher. |
Module Contents¶
- httk.store.query.protocols.ID_FIELD: Final = '__id'[source]¶
The backend field name used for the served entry identifier.
- exception httk.store.query.protocols.UnsupportedQueryError[source]¶
Bases:
ValueErrorReport that a valid query operation is outside a store’s supported profile.
Bases:
RuntimeErrorReport that a store cannot provide an exact query count.
- exception httk.store.query.protocols.NoResultError[source]¶
Bases:
LookupErrorReport that a result-set
one()operation found no matching result.
- exception httk.store.query.protocols.MultipleResultsError[source]¶
Bases:
LookupErrorReport that a result-set
one()operation found multiple results.
- exception httk.store.query.protocols.PaginationCursorError[source]¶
Bases:
ValueErrorReport that a continuation cursor is malformed, expired, or belongs to another result plan.
- class httk.store.query.protocols.PageOrder[source]¶
Order a continuation page by one named scalar result projection.
nameidentifies the name supplied toresults(), never a backend column object. The result-set implementation validates that it is a root scalar projection before it generates SQL.- Parameters:
name – The declared scalar output name used for ordering.
descending – Whether to order this field in descending order.
nulls – Whether null values sort first or last.
- class httk.store.query.protocols.ContinuationToken[source]¶
Bases:
strCarry an opaque URL-safe continuation value.
It is a
strsubclass so normal JSON serializers preserve it as a scalar value. Applications should pass a token returned by a page back unchanged; data backends validate its version, structure, and result-plan fingerprint before using any decoded value as a bound parameter.- Parameters:
value – The opaque continuation value.
- class httk.store.query.protocols.ResultPage[source]¶
Represent an immutable continuation-page result.
rowsis always a tuple. Returned rows are ordinary persistent result rows, not the expiring proxies produced bySqlResultSet.cursor().totalis populated only when the caller explicitly asks for it.- Parameters:
rows – The persistent rows returned by the page.
next – The token for the next page, if one exists.
previous – The token for the previous page, if one exists.
total – The exact result count when requested, otherwise
None.
- rows: tuple[ResultRowLike, ...][source]¶
- next: ContinuationToken | None[source]¶
- previous: ContinuationToken | None[source]¶
- class httk.store.query.protocols.PageableResultSetLike[source]¶
Bases:
ProtocolExpose optional continuation-page capability on a frozen result set.
This deliberately extends neither
ResultSetLikenorSearcher: stores that do not support seek pagination remain fully conforming to the required portable contracts.
- class httk.store.query.protocols.ResultRow(values, names, resolver=None, guard=None)[source]¶
Represent one named result row by position, name, or attribute.
- Parameters:
- class httk.store.query.protocols.ResultRowLike[source]¶
Bases:
ProtocolRequire named access to one result row.
- class httk.store.query.protocols.ResultSetLike[source]¶
Bases:
ProtocolRequire the common operations of a materialized result set.
- class httk.store.query.protocols.SearchExpression[source]¶
Bases:
ProtocolRequire composable backend search expressions.
- class httk.store.query.protocols.SearchField[source]¶
Bases:
ProtocolExpose a queryable field of a search variable.
In addition to the methods below, fields support the rich comparison operators (
==,!=,<,<=,>,>=), returningSearchExpression. The handlers invoke those viagetattr(field, '__eq__')(value)since the comparison dunders cannot be typed as expression-returning.The three string-matching methods take literal text: no wildcard or pattern syntax whatsoever crosses this contract, so
%and_(and any other metacharacter) match themselves. A backend is therefore free to implement them with SQLLIKEover an escaped pattern, with a regular expression, or with a full-text index — the choice is invisible here.- is_in(*values)[source]¶
Match a root scalar field whose value is one of
values.Noneis an explicit member: it matches a null field value, and its negation excludes nulls rather than inheriting SQL’s three-valuedNOT IN (..., NULL)behavior.Backends define the corresponding semantics for child or set fields; for example, a backend may use the existing
has_only-style all-values reading for a child field.
- class httk.store.query.protocols.SearchVariable[source]¶
Bases:
ProtocolBind a query variable to a target type whose attributes yield fields.
always_true/always_falseare reserved names: they are real methods of the variable, never stored fields resolved through__getattr__. They exist so a translation layer can express a constant truth value without inventing a probe field. Afield == fieldprobe is NULL-unsound, since it yields NULL (not true) for a NULL field.links.<name>is a reserved relationship namespace: usable as a predicate root (v.links.p == other, field chaining, set operations) and, on its own, as a set-valued output declared throughSearcher.results().
- class httk.store.query.protocols.Searcher[source]¶
Bases:
ProtocolBuild one query; consume it through
Searcher.results().The expressions received by
addare always ones produced by this same backend’s search variables, so implementations may type them as their own expression class; a backend that needs a second (post-filter) evaluation position decides that from the expression itself, not from the caller.
- class httk.store.query.protocols.BackendSearcher[source]¶
Bases:
Searcher,ProtocolA searcher plus its private, backend-internal raw query surface.
Result sets, the federated store, stored-property streaming and entry providers build a query and consume its matches through the raw path below; user code consumes a query through
Searcher.results()instead.