"""Define `Annotated` columns for SQLAlchemy models.Examples: * `INT_PK`: An auto-incrementing, primary key integer value. * `STR_10`: A `VARCHAR(10)` column. * `STR_255`: A `VARCHAR(255)` column."""from__future__importannotationsimportsqlalchemyassaimportsqlalchemy.ormassofromtyping_extensionsimportAnnotated## Annotated auto-incrementing integer primary key columnINT_PK=Annotated[int,so.mapped_column(sa.INTEGER,primary_key=True,autoincrement=True,unique=True)]## SQLAlchemy VARCHAR(10)STR_10=Annotated[str,so.mapped_column(sa.VARCHAR(10))]## SQLAlchemy VARCHAR(255)STR_255=Annotated[str,so.mapped_column(sa.VARCHAR(255))]
Custom Column Types
Example CustomJson column type
Column type for converting objects to JSON for storage in SQLAlchemy. Inputs can be a list of types, like list[int], list[str], a Python dict, or any other JSON-serializable object.