当前位置: 首页>>代码示例>>Python>>正文


Python declarative.AbstractConcreteBase方法代码示例

本文整理汇总了Python中sqlalchemy.ext.declarative.AbstractConcreteBase方法的典型用法代码示例。如果您正苦于以下问题:Python declarative.AbstractConcreteBase方法的具体用法?Python declarative.AbstractConcreteBase怎么用?Python declarative.AbstractConcreteBase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.ext.declarative的用法示例。


在下文中一共展示了declarative.AbstractConcreteBase方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _sa_raise_deferred_config

# 需要导入模块: from sqlalchemy.ext import declarative [as 别名]
# 或者: from sqlalchemy.ext.declarative import AbstractConcreteBase [as 别名]
def _sa_raise_deferred_config(cls):
        raise orm_exc.UnmappedClassError(
            cls,
            msg="Class %s is a subclass of AbstractConcreteBase and "
            "has a mapping pending until all subclasses are defined. "
            "Call the sqlalchemy.orm.configure_mappers() function after "
            "all subclasses have been defined to "
            "complete the mapping of this class."
            % orm_exc._safe_cls_name(cls),
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:12,代码来源:api.py

示例2: test_abstract_concrete_extension

# 需要导入模块: from sqlalchemy.ext import declarative [as 别名]
# 或者: from sqlalchemy.ext.declarative import AbstractConcreteBase [as 别名]
def test_abstract_concrete_extension(self):
        class Employee(AbstractConcreteBase, Base, fixtures.ComparableEntity):
            pass

        class Manager(Employee):
            __tablename__ = "manager"
            employee_id = Column(
                Integer, primary_key=True, test_needs_autoincrement=True
            )
            name = Column(String(50))
            golf_swing = Column(String(40))
            __mapper_args__ = {
                "polymorphic_identity": "manager",
                "concrete": True,
            }

        class Boss(Manager):
            __tablename__ = "boss"
            employee_id = Column(
                Integer, primary_key=True, test_needs_autoincrement=True
            )
            name = Column(String(50))
            golf_swing = Column(String(40))
            __mapper_args__ = {
                "polymorphic_identity": "boss",
                "concrete": True,
            }

        class Engineer(Employee):
            __tablename__ = "engineer"
            employee_id = Column(
                Integer, primary_key=True, test_needs_autoincrement=True
            )
            name = Column(String(50))
            primary_language = Column(String(40))
            __mapper_args__ = {
                "polymorphic_identity": "engineer",
                "concrete": True,
            }

        self._roundtrip(Employee, Manager, Engineer, Boss) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:43,代码来源:test_inheritance.py

示例3: test_column_attr_names

# 需要导入模块: from sqlalchemy.ext import declarative [as 别名]
# 或者: from sqlalchemy.ext.declarative import AbstractConcreteBase [as 别名]
def test_column_attr_names(self):
        """test #3480"""

        class Document(Base, AbstractConcreteBase):
            documentType = Column("documenttype", String)

        class Offer(Document):
            __tablename__ = "offers"

            id = Column(Integer, primary_key=True)
            __mapper_args__ = {"polymorphic_identity": "offer"}

        configure_mappers()
        session = Session()
        self.assert_compile(
            session.query(Document),
            "SELECT pjoin.documenttype AS pjoin_documenttype, "
            "pjoin.id AS pjoin_id, pjoin.type AS pjoin_type FROM "
            "(SELECT offers.documenttype AS documenttype, offers.id AS id, "
            "'offer' AS type FROM offers) AS pjoin",
        )

        self.assert_compile(
            session.query(Document.documentType),
            "SELECT pjoin.documenttype AS pjoin_documenttype FROM "
            "(SELECT offers.documenttype AS documenttype, offers.id AS id, "
            "'offer' AS type FROM offers) AS pjoin",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:30,代码来源:test_inheritance.py

示例4: test_abstract_concrete_base_didnt_configure

# 需要导入模块: from sqlalchemy.ext import declarative [as 别名]
# 或者: from sqlalchemy.ext.declarative import AbstractConcreteBase [as 别名]
def test_abstract_concrete_base_didnt_configure(self):
        class Employee(AbstractConcreteBase, Base, fixtures.ComparableEntity):
            pass

        assert_raises_message(
            orm_exc.UnmappedClassError,
            "Class test.ext.declarative.test_inheritance.Employee is a "
            "subclass of AbstractConcreteBase and has a mapping pending "
            "until all subclasses are defined. Call the "
            r"sqlalchemy.orm.configure_mappers\(\) function after all "
            "subclasses have been defined to complete the "
            "mapping of this class.",
            Session().query,
            Employee,
        )

        configure_mappers()

        # no subclasses yet.
        assert_raises_message(
            orm_exc.UnmappedClassError,
            ".*and has a mapping pending",
            Session().query,
            Employee,
        )

        class Manager(Employee):
            __tablename__ = "manager"
            employee_id = Column(
                Integer, primary_key=True, test_needs_autoincrement=True
            )
            name = Column(String(50))
            golf_swing = Column(String(40))
            __mapper_args__ = {
                "polymorphic_identity": "manager",
                "concrete": True,
            }

        # didnt call configure_mappers() again
        assert_raises_message(
            orm_exc.UnmappedClassError,
            ".*and has a mapping pending",
            Session().query,
            Employee,
        )

        configure_mappers()

        self.assert_compile(
            Session().query(Employee),
            "SELECT pjoin.employee_id AS pjoin_employee_id, "
            "pjoin.name AS pjoin_name, pjoin.golf_swing AS pjoin_golf_swing, "
            "pjoin.type AS pjoin_type FROM (SELECT manager.employee_id "
            "AS employee_id, manager.name AS name, manager.golf_swing AS "
            "golf_swing, 'manager' AS type FROM manager) AS pjoin",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:58,代码来源:test_inheritance.py

示例5: test_abstract_concrete_extension_descriptor_refresh

# 需要导入模块: from sqlalchemy.ext import declarative [as 别名]
# 或者: from sqlalchemy.ext.declarative import AbstractConcreteBase [as 别名]
def test_abstract_concrete_extension_descriptor_refresh(self):
        class Employee(AbstractConcreteBase, Base, fixtures.ComparableEntity):
            @declared_attr
            def name(cls):
                return Column(String(50))

        class Manager(Employee):
            __tablename__ = "manager"
            employee_id = Column(
                Integer, primary_key=True, test_needs_autoincrement=True
            )
            paperwork = Column(String(10))
            __mapper_args__ = {
                "polymorphic_identity": "manager",
                "concrete": True,
            }

        class Engineer(Employee):
            __tablename__ = "engineer"
            employee_id = Column(
                Integer, primary_key=True, test_needs_autoincrement=True
            )

            @property
            def paperwork(self):
                return "p"

            __mapper_args__ = {
                "polymorphic_identity": "engineer",
                "concrete": True,
            }

        Base.metadata.create_all()
        sess = Session()
        sess.add(Engineer(name="d"))
        sess.commit()

        # paperwork is excluded because there's a descritor; so it is
        # not in the Engineers mapped properties at all, though is inside the
        # class manager.   Maybe it shouldn't be in the class manager either.
        assert "paperwork" in Engineer.__mapper__.class_manager
        assert "paperwork" not in Engineer.__mapper__.attrs.keys()

        # type currently does get mapped, as a
        # ConcreteInheritedProperty, which means, "ignore this thing inherited
        # from the concrete base".   if we didn't specify concrete=True, then
        # this one gets stuck in the error condition also.
        assert "type" in Engineer.__mapper__.class_manager
        assert "type" in Engineer.__mapper__.attrs.keys()

        e1 = sess.query(Engineer).first()
        eq_(e1.name, "d")
        sess.expire(e1)
        eq_(e1.name, "d") 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:56,代码来源:test_inheritance.py

示例6: test_ok_to_override_type_from_abstract

# 需要导入模块: from sqlalchemy.ext import declarative [as 别名]
# 或者: from sqlalchemy.ext.declarative import AbstractConcreteBase [as 别名]
def test_ok_to_override_type_from_abstract(self):
        class Employee(AbstractConcreteBase, Base, fixtures.ComparableEntity):
            pass

        class Manager(Employee):
            __tablename__ = "manager"
            employee_id = Column(
                Integer, primary_key=True, test_needs_autoincrement=True
            )
            name = Column(String(50))
            golf_swing = Column(String(40))

            @property
            def type(self):
                return "manager"

            __mapper_args__ = {
                "polymorphic_identity": "manager",
                "concrete": True,
            }

        class Boss(Manager):
            __tablename__ = "boss"
            employee_id = Column(
                Integer, primary_key=True, test_needs_autoincrement=True
            )
            name = Column(String(50))
            golf_swing = Column(String(40))

            @property
            def type(self):
                return "boss"

            __mapper_args__ = {
                "polymorphic_identity": "boss",
                "concrete": True,
            }

        class Engineer(Employee):
            __tablename__ = "engineer"
            employee_id = Column(
                Integer, primary_key=True, test_needs_autoincrement=True
            )
            name = Column(String(50))
            primary_language = Column(String(40))

            @property
            def type(self):
                return "engineer"

            __mapper_args__ = {
                "polymorphic_identity": "engineer",
                "concrete": True,
            }

        self._roundtrip(Employee, Manager, Engineer, Boss, explicit_type=True) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:58,代码来源:test_inheritance.py


注:本文中的sqlalchemy.ext.declarative.AbstractConcreteBase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。