class Rule(BaseModel):
"""Used to identify the statute based on a category and identifier. The `col` and `index` field attributes are not native to Pydantic; these are populated in anticipation of future use via the `sqlpyd` library."""
cat: StatuteCategory = Field(
col=str,
index=True,
)
idx: constr(to_lower=True) = Field( # type: ignore
...,
regex="[a-z0-9-]+",
col=str,
index=True,
)
This becomes usable in the following context:
class CodeRow(Page, Rule, TableConfig): # see Rule use here
__prefix__ = "lex"
__tablename__ = "codifications"
__indexes__ = [["statute_category", "statute_serial_id"]]
statute_id: str | None = Field(
None, col=str, fk=(StatuteRow.__tablename__, "id")
)
TableConfig is sqlpyd-native and detects that the fields cat and idx are going to be part of the database table "codifications".
This becomes usable in the following context:
TableConfig is
sqlpyd
-native and detects that the fieldscat
andidx
are going to be part of the database table "codifications".