r"""Map a class imperatively. In this form of mapping, the class is not scanned for any mapping information. Instead, all mapping constructs are passed as arguments. This method is intended to be fully equivalent to the now-removed SQLAlchemy ``mapper()`` f
(
self,
class_: Type[_O],
local_table: Optional[FromClause] = None,
**kw: Any,
)
| 1867 | return cls.__mapper__ class="cm"># type: ignore |
| 1868 | |
| 1869 | def map_imperatively( |
| 1870 | self, |
| 1871 | class_: Type[_O], |
| 1872 | local_table: Optional[FromClause] = None, |
| 1873 | **kw: Any, |
| 1874 | ) -> Mapper[_O]: |
| 1875 | rclass="st">"""Map a class imperatively. |
| 1876 | |
| 1877 | In this form of mapping, the class is not scanned for any mapping |
| 1878 | information. Instead, all mapping constructs are passed as |
| 1879 | arguments. |
| 1880 | |
| 1881 | This method is intended to be fully equivalent to the now-removed |
| 1882 | SQLAlchemy ``mapper()`` function, except that it&class="cm">#x27;s in terms of |
| 1883 | a particular registry. |
| 1884 | |
| 1885 | E.g.:: |
| 1886 | |
| 1887 | from sqlalchemy.orm import registry |
| 1888 | |
| 1889 | mapper_registry = registry() |
| 1890 | |
| 1891 | my_table = Table( |
| 1892 | class="st">"my_table", |
| 1893 | mapper_registry.metadata, |
| 1894 | Column(class="st">"id", Integer, primary_key=True), |
| 1895 | ) |
| 1896 | |
| 1897 | |
| 1898 | class MyClass: |
| 1899 | pass |
| 1900 | |
| 1901 | |
| 1902 | mapper_registry.map_imperatively(MyClass, my_table) |
| 1903 | |
| 1904 | See the section :ref:`orm_imperative_mapping` for complete background |
| 1905 | and usage examples. |
| 1906 | |
| 1907 | :param class\_: The class to be mapped. Corresponds to the |
| 1908 | :paramref:`_orm.Mapper.class_` parameter. |
| 1909 | |
| 1910 | :param local_table: the :class:`_schema.Table` or other |
| 1911 | :class:`_sql.FromClause` object that is the subject of the mapping. |
| 1912 | Corresponds to the |
| 1913 | :paramref:`_orm.Mapper.local_table` parameter. |
| 1914 | |
| 1915 | :param \**kw: all other keyword arguments are passed to the |
| 1916 | :class:`_orm.Mapper` constructor directly. |
| 1917 | |
| 1918 | .. seealso:: |
| 1919 | |
| 1920 | :ref:`orm_imperative_mapping` |
| 1921 | |
| 1922 | :ref:`orm_declarative_mapping` |
| 1923 | |
| 1924 | class="st">""" |
| 1925 | return _ORMClassConfigurator._mapper(self, class_, local_table, kw) |
| 1926 |