Standalone function form of :meth:`_orm.registry.mapped_as_dataclass` which may have better compatibility with mypy. The :class:`_orm.registry` is passed as the first argument to the decorator. e.g.:: from sqlalchemy.orm import Mapped from sqlalchemy.orm import map
(
registry: RegistryType,
/,
*,
init: Union[_NoArg, bool] = _NoArg.NO_ARG,
repr: Union[_NoArg, bool] = _NoArg.NO_ARG, # noqa: A002
eq: Union[_NoArg, bool] = _NoArg.NO_ARG,
order: Union[_NoArg, bool] = _NoArg.NO_ARG,
unsafe_hash: Union[_NoArg, bool] = _NoArg.NO_ARG,
match_args: Union[_NoArg, bool] = _NoArg.NO_ARG,
kw_only: Union[_NoArg, bool] = _NoArg.NO_ARG,
dataclass_callable: Union[
_NoArg, Callable[..., Type[Any]]
] = _NoArg.NO_ARG,
)
| 2120 | ), |
| 2121 | ) |
| 2122 | def mapped_as_dataclass( |
| 2123 | registry: RegistryType, |
| 2124 | /, |
| 2125 | *, |
| 2126 | init: Union[_NoArg, bool] = _NoArg.NO_ARG, |
| 2127 | repr: Union[_NoArg, bool] = _NoArg.NO_ARG, # noqa: A002 |
| 2128 | eq: Union[_NoArg, bool] = _NoArg.NO_ARG, |
| 2129 | order: Union[_NoArg, bool] = _NoArg.NO_ARG, |
| 2130 | unsafe_hash: Union[_NoArg, bool] = _NoArg.NO_ARG, |
| 2131 | match_args: Union[_NoArg, bool] = _NoArg.NO_ARG, |
| 2132 | kw_only: Union[_NoArg, bool] = _NoArg.NO_ARG, |
| 2133 | dataclass_callable: Union[ |
| 2134 | _NoArg, Callable[..., Type[Any]] |
| 2135 | ] = _NoArg.NO_ARG, |
| 2136 | ) -> Callable[[Type[_O]], Type[_O]]: |
| 2137 | """Standalone function form of :meth:`_orm.registry.mapped_as_dataclass` |
| 2138 | which may have better compatibility with mypy. |
| 2139 | |
| 2140 | The :class:`_orm.registry` is passed as the first argument to the |
| 2141 | decorator. |
| 2142 | |
| 2143 | e.g.:: |
| 2144 | |
| 2145 | from sqlalchemy.orm import Mapped |
| 2146 | from sqlalchemy.orm import mapped_as_dataclass |
| 2147 | from sqlalchemy.orm import mapped_column |
| 2148 | from sqlalchemy.orm import registry |
| 2149 | |
| 2150 | some_registry = registry() |
| 2151 | |
| 2152 | |
| 2153 | @mapped_as_dataclass(some_registry) |
| 2154 | class Relationships: |
| 2155 | __tablename__ = "relationships" |
| 2156 | |
| 2157 | entity_id1: Mapped[int] = mapped_column(primary_key=True) |
| 2158 | entity_id2: Mapped[int] = mapped_column(primary_key=True) |
| 2159 | level: Mapped[int] = mapped_column(Integer) |
| 2160 | |
| 2161 | .. versionadded:: 2.0.44 |
| 2162 | |
| 2163 | """ |
| 2164 | |
| 2165 | def decorate(cls: Type[_O]) -> Type[_O]: |
| 2166 | _generate_dc_transforms( |
| 2167 | init=init, |
| 2168 | repr=repr, |
| 2169 | eq=eq, |
| 2170 | order=order, |
| 2171 | unsafe_hash=unsafe_hash, |
| 2172 | match_args=match_args, |
| 2173 | kw_only=kw_only, |
| 2174 | dataclass_callable=dataclass_callable, |
| 2175 | cls_=cls, |
| 2176 | ) |
| 2177 | _ORMClassConfigurator._as_declarative(registry, cls, cls.__dict__) |
| 2178 | return cls |
| 2179 |
no outgoing calls