httk.store.db¶
The SQL storage layer of httk-store: store frozen dataclasses in relational databases.
This subpackage turns plain frozen dataclasses — declared storable with the
stdlib-only marker vocabulary in httk-core (Indexed, Unique, Skip,
Shape, StorageInfo, stored_property) — into relational storage.
The pure-Python foundation lives here:
httk.store.db.schema—resolve_schema()reads a storable class into aTableSchema, the single source of truth for DDL, inserts, selects, and reconstruction;httk.store.db.codecs— theValueCodecregistry with exact, round-trippable encodings for rationals, surds, and datetimes;httk.core.storage—canonical_formandcontent_id, the content identity used for deduplication.
These modules import cleanly without sqlalchemy. The SQL layer proper builds
on them and requires the httk-store[db] extra (sqlalchemy):
Database— the engine wrapper naming where data lives (Database.sqlite(...),Database.duckdb(...), or the Keeper-backedDatabase.clickhouse(...));SqlStore— save/fetch/dedup/transactions for storable instances, on top of the schema-to-table mapping inhttk.store.db.mapping;SqlSearcher(fromsearcher()) — the query DSL implementing thehttk.store.querysearch protocols, withSqlVariable,SqlColumnandSqlExpression;StoreEntryProvider— the bridge that serves stored classes through the neutralEntryProvidercontract (e.g. as an OPTIMADE API via httk-serve);optimade_filter_searcher()— OPTIMADE-filter querying over storable classes, tying the generic filter translation inhttk.store.query.optimade_filtersto the SQL layer.
The sqlalchemy-backed names are imported lazily on first attribute access, so
import httk.store.db keeps working without sqlalchemy; touching them
without sqlalchemy installed raises ImportError naming the extra.
Submodules¶
- httk.store.db.bulk
- httk.store.db.bulk_deferred
- httk.store.db.bulk_parallel
- httk.store.db.clickhouse
- httk.store.db.codecs
- httk.store.db.engine
- httk.store.db.entry_provider
- httk.store.db.fsck
- httk.store.db.graph
- httk.store.db.layout
- httk.store.db.mapping
- httk.store.db.optimade
- httk.store.db.paging
- httk.store.db.results
- httk.store.db.rows
- httk.store.db.schema
- httk.store.db.searcher
- httk.store.db.store
- httk.store.db.stored_federation
- httk.store.db.stored_properties
Exceptions¶
Report that a result-set |
|
Report that a result-set |
|
A class or field cannot be resolved into a storage schema; the message names both. |
Classes¶
Represent one named result row by position, name, or attribute. |
|
An exact encoding of one Python value type across one or more scalar columns. |
Functions¶
|
Register |
|
Register an external |
|
Resolve (and cache) the |
Package Contents¶
- exception httk.store.db.MultipleResultsError[source]¶
Bases:
LookupErrorReport that a result-set
one()operation found multiple results.
- exception httk.store.db.NoResultError[source]¶
Bases:
LookupErrorReport that a result-set
one()operation found no matching result.
- class httk.store.db.ResultRow(values, names, resolver=None, guard=None)[source]¶
Represent one named result row by position, name, or attribute.
- Parameters:
- class httk.store.db.ValueCodec[source]¶
An exact encoding of one Python value type across one or more scalar columns.
The
columnstuple gives(suffix, kind)pairs: the empty suffix names the field’s own column (by convention the query column), non-empty suffixes are appended to the field name by the schema layer (e.g."_exact").encodeanddecodemap a value to and from the column-value tuple, incolumnsorder, and must round-trip exactly.- Parameters:
name – The registry name of the codec.
python_type – The Python type stored by the codec.
columns – The column suffix and scalar-kind pairs encoded by the codec.
encode – The function that encodes a value into column values.
decode – The function that reconstructs a value from column values.
query_suffix – The suffix of the query and index column.
- columns: tuple[tuple[str, httk.store.db.codecs.ScalarKind], ...]¶
The
(column name suffix, scalar kind)pairs the codec encodes into.
- encode: collections.abc.Callable[[Any], tuple[Any, Ellipsis]]¶
Encode a value into one scalar per entry of
columns, in order.
- decode: collections.abc.Callable[[tuple[Any, Ellipsis]], Any]¶
Recover the exact value from the tuple produced by
encode.
- httk.store.db.register_value_codec(codec)[source]¶
Register
codecin the value-codec registry.- Parameters:
codec (ValueCodec) – The codec to register.
- Returns:
None.
- Raises:
ValueError – If the codec name or Python type is already registered.
- Return type:
None
- exception httk.store.db.SchemaError[source]¶
Bases:
ExceptionA class or field cannot be resolved into a storage schema; the message names both.
- httk.store.db.register_schema_override(cls, info)[source]¶
Register an external
StorageInfofor a class that cannot declare one.The registered info is used by
resolve_schema()whenever no explicitoverrideargument is passed, and takes precedence over a__httk_storage__declaration on the class itself.- Parameters:
cls (type) – The storable class whose schema should be overridden.
info (httk.core.storage.StorageInfo) – The external storage information to register.
- Returns:
None.
- Return type:
None
- httk.store.db.resolve_schema(cls, *, override=None)[source]¶
Resolve (and cache) the
TableSchemaof a storable dataclass.The effective
StorageInfois, in order of precedence: the explicitoverrideargument, an info registered viaregister_schema_override(), the class’s own__httk_storage__attribute, or defaults. Results are cached per(class, effective override), so repeated calls return the sameTableSchemaobject. Reference cycles (a class referencing itself, or mutually referencing classes) are allowed and resolve without recursion loops.- Parameters:
cls (type) – The storable class to resolve.
override (httk.core.storage.StorageInfo | None) – External storage information taking precedence over declarations.
- Returns:
The cached resolved table schema.
- Raises:
httk.store.db.schema.SchemaError – If the class is not a frozen dataclass or one of its fields cannot be resolved; the diagnostic names the class and field.
- Return type: