Architecture¶
Pydantic Model
↓
inspectors.inspect_model → FieldDescriptor[]
↓
constraints.extract_constraints → Constraint IR (PatternSpec / markers)
↓
cache.ModelIRCache (optional) → ModelIR
↓
columns.resolve_column
↓
translators.TranslatorRegistry.translate
↓
Rule dictionary (+ diagnostics)
SQLRules is a pure compiler pipeline with two phases:
Phase 1 — static model IR
Inspect the Pydantic model and preserve field declaration order.
Extract supported constraints into a dialect-neutral IR.
Cache immutable
ModelIRkeyed by model class (optional).
Phase 2 — bind and translate
Resolve each constrained field to a SQLAlchemy column.
Translate each IR constraint into one SQLAlchemy expression.
Assemble expressions into
dict[str, list[ColumnElement[bool]]].
The compiler never connects to a database, executes SQL, or renders SQL strings. See COMPILER.md and INTERNAL_API.md for module-level detail.