MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / map_declaratively

Method map_declaratively

lib/sqlalchemy/orm/decl_api.py:1777–1825  ·  view source on GitHub ↗

Map a class declaratively. In this form of mapping, the class is scanned for mapping information, including for columns to be associated with a table, and/or an actual table object. Returns the :class:`_orm.Mapper` object. E.g.:: from sqlalchem

(self, cls: Type[_O])

Source from the content-addressed store, hash-verified

1775 return decorate
1776
1777 def map_declaratively(self, cls: Type[_O]) -> Mapper[_O]:
1778 """Map a class declaratively.
1779
1780 In this form of mapping, the class is scanned for mapping information,
1781 including for columns to be associated with a table, and/or an
1782 actual table object.
1783
1784 Returns the :class:`_orm.Mapper` object.
1785
1786 E.g.::
1787
1788 from sqlalchemy.orm import registry
1789
1790 mapper_registry = registry()
1791
1792
1793 class Foo:
1794 __tablename__ = "some_table"
1795
1796 id = Column(Integer, primary_key=True)
1797 name = Column(String)
1798
1799
1800 mapper = mapper_registry.map_declaratively(Foo)
1801
1802 This function is more conveniently invoked indirectly via either the
1803 :meth:`_orm.registry.mapped` class decorator or by subclassing a
1804 declarative metaclass generated from
1805 :meth:`_orm.registry.generate_base`.
1806
1807 See the section :ref:`orm_declarative_mapping` for complete
1808 details and examples.
1809
1810 :param cls: class to be mapped.
1811
1812 :return: a :class:`_orm.Mapper` object.
1813
1814 .. seealso::
1815
1816 :ref:`orm_declarative_mapping`
1817
1818 :meth:`_orm.registry.mapped` - more common decorator interface
1819 to this function.
1820
1821 :meth:`_orm.registry.map_imperatively`
1822
1823 """
1824 _as_declarative(self, cls, cls.__dict__)
1825 return cls.__mapper__ # type: ignore
1826
1827 def map_imperatively(
1828 self,

Calls 1

_as_declarativeFunction · 0.85