registry
registry
¶
Model-driven schema registry for unified SQLite schema management.
Maps Pydantic BaseModel and dataclass models to SQLite table schemas, enabling automatic DDL generation, upsert SQL, and schema drift detection.
Attributes¶
Classes¶
FieldSpec
dataclass
¶
Unified field descriptor for both Pydantic and dataclass models.
TableMapping
dataclass
¶
Declares the mapping between a Python model and a SQLite table.
This is the single source of truth for schema generation, save/load, and drift detection.
Attributes¶
primary_key
class-attribute
instance-attribute
¶
Primary key column(s). Refers to SQL column names (after renames).
renames
class-attribute
instance-attribute
¶
model_field_name → sql_column_name renames.
exclude
class-attribute
instance-attribute
¶
Model field names to exclude from this table.
extra_columns
class-attribute
instance-attribute
¶
Additional columns not from the model: [(name, full_definition), ...].
ColumnSource
dataclass
¶
Functions¶
get_sqlite_type
¶
Map a Python type annotation to a SQLite column type string.
Source code in src/marianne/schema/registry.py
get_field_specs
¶
Extract field specifications from a Pydantic or dataclass model.
Returns fields in declaration order.
Source code in src/marianne/schema/registry.py
get_column_sources
¶
Get ordered column sources for building SQL values.
Returns extra_columns first, then model fields (excluding excluded fields).
Source code in src/marianne/schema/registry.py
get_expected_columns
¶
Get expected {column_name: sqlite_type} for a mapping.
Includes extra columns and all non-excluded model fields.
Source code in src/marianne/schema/registry.py
generate_create_table
¶
Generate CREATE TABLE IF NOT EXISTS SQL from a TableMapping.
Source code in src/marianne/schema/registry.py
generate_upsert
¶
Generate INSERT ... ON CONFLICT DO UPDATE SQL.
Returns:
| Type | Description |
|---|---|
(sql_template, column_sources)
|
SQL with ? placeholders and the |
list[ColumnSource]
|
ordered ColumnSource list matching placeholder positions. |
Source code in src/marianne/schema/registry.py
get_state_registry
¶
Get the state DB registry (lazy-built on first access).