Supported Constraint Mapping¶
Constraint |
SQLAlchemy expression |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IR ( |
|
IR ( |
Dialect markers (sqlrules.markers)¶
Marker |
IR operator |
Typical plugin translation |
|---|---|---|
|
|
JSONB / JSON containment |
|
|
JSON key existence |
|
|
PostgreSQL array containment |
|
|
PostgreSQL array overlap |
|
|
PostgreSQL range |
|
|
PostgreSQL range |
|
|
MySQL |
Accepted input forms for portable constraints include Field(...),
annotated_types primitives, Interval, Len, conint/constr, and
StringConstraints (length attributes; pattern becomes PatternSpec IR).
Constraints without a deterministic SQL equivalent are rejected by default. See TYPE_SUPPORT.md and ERRORS.md.
To translate pattern, type_check, or markers, use a dialect plugin:
from sqlrules import Compiler, JsonContains
from sqlrules_postgresql import PostgresPlugin
compiler = Compiler(
plugins=[PostgresPlugin()],
dialect="postgresql",
emit_type_checks=True,
)
from sqlrules.constraints import pattern_text
from sqlrules.translators import default_registry
registry = default_registry()
registry.register_constraint(
"pattern",
lambda c, col, ctx: col.op("~")(pattern_text(c.value)[0]),
on_conflict="replace",
)
compiler = sqlrules.Compiler(registry=registry)