Example #1
0
    def _construct_model(self, archetype):
        parent = archetype.config.model
        attrs = {"id": ForeignKey(parent.id, nullable=False, primary_key=True)}

        constructor = FieldConstructor()
        if archetype.properties:
            for name, field in sorted(archetype.properties.structure.iteritems()):
                attrs[name] = constructor.construct(field)

        tablename = safe_table_name(archetype.id.replace(":", "_"), archetype.config.prefix)
        model = self.schema.construct_model(parent, tablename, attrs, tablename, polymorphic_identity=archetype.id)

        self.schema.create_or_update_table(model.__table__)
        return model
Example #2
0
    def _construct_table(self, archetype):
        metadata = MetaData()
        parent = Table(
            archetype.config.model.__tablename__, metadata, Text(name="id", nullable=False, primary_key=True)
        )

        tablename = safe_table_name(archetype.id.replace(":", "_"), archetype.config.prefix)
        table = Table(
            tablename,
            metadata,
            ForeignKey(name="id", column=parent.c.id, type_=TextType(), nullable=False, primary_key=True),
        )

        return table
Example #3
0
    def _construct_table(self, archetype):
        metadata = MetaData()
        parent = Table(archetype.config.model.__tablename__, metadata,
                       Text(name='id', nullable=False, primary_key=True))

        tablename = safe_table_name(archetype.id.replace(':', '_'),
                                    archetype.config.prefix)
        table = Table(
            tablename, metadata,
            ForeignKey(name='id',
                       column=parent.c.id,
                       type_=TextType(),
                       nullable=False,
                       primary_key=True))

        return table
Example #4
0
    def _construct_model(self, archetype):
        parent = archetype.config.model
        attrs = {'id': ForeignKey(parent.id, nullable=False, primary_key=True)}

        constructor = FieldConstructor()
        if archetype.properties:
            for name, field in sorted(
                    archetype.properties.structure.iteritems()):
                attrs[name] = constructor.construct(field)

        tablename = safe_table_name(archetype.id.replace(':', '_'),
                                    archetype.config.prefix)
        model = self.schema.construct_model(parent,
                                            tablename,
                                            attrs,
                                            tablename,
                                            polymorphic_identity=archetype.id)

        self.schema.create_or_update_table(model.__table__)
        return model