httk.data.db.mapping¶
Schema-to-SQL mapping: build SQLAlchemy Core tables from resolved TableSchema IR.
table_for() turns one resolved schema into a sqlalchemy.Table
registered in a sqlalchemy.MetaData (idempotently: an already-built
table is returned as-is), recursing into referenced and child-element storable
classes so that every foreign-key target exists in the same metadata.
sqlalchemy_metadata() is the convenience wrapper that maps a batch of
schemas into one fresh metadata.
The relational layout produced here is exactly the one the schema IR documents, plus the store-managed columns:
every parent table gets an
sidinteger primary key (autoincrementing, with an attached<table>_sid_seqsequence for dialects such as DuckDB that need one; SQLite ignores it) and — only under the"content_id"dedup policy — a unique-indexedcontent_idtext column;every child table gets a
<parent table>_sidinteger foreign key (NOT NULL, indexed) and a<field>_indexinteger ordering column ahead of its element columns; storable elements become a<field>_sidforeign key to the element class’s table.
Index names are deterministic and table-scoped — ix_<table>_<column> for
plain indexes, uq_<table>_<column> for unique ones, columns joined by
underscores for composites — truncated with a stable hash suffix when they
would exceed common identifier-length limits.
Attributes¶
The store-managed integer primary-key column present on every table. |
|
The store-managed content-identity column of tables with the |
Functions¶
|
A fresh |
|
The |
Module Contents¶
- httk.data.db.mapping.SID_COLUMN: Final = 'sid'[source]¶
The store-managed integer primary-key column present on every table.
- httk.data.db.mapping.CONTENT_ID_COLUMN: Final = 'content_id'[source]¶
The store-managed content-identity column of tables with the
"content_id"dedup policy.
- httk.data.db.mapping.sqlalchemy_metadata(schemas: collections.abc.Iterable[httk.data.db.schema.TableSchema]) sqlalchemy.MetaData[source]¶
A fresh
sqlalchemy.MetaDataholding the tables ofschemas(recursively).
- httk.data.db.mapping.table_for(schema: httk.data.db.schema.TableSchema, metadata: sqlalchemy.MetaData) sqlalchemy.Table[source]¶
The
sqlalchemy.Tableofschemawithinmetadata, building it on first use.Building is idempotent per metadata — if the table is already registered it is returned unchanged — and recursive: the child tables of the schema and the tables of every referenced storable class (reference fields and storable child elements alike) are built into the same metadata, so all foreign keys resolve.